OSDN Git Service

3e17909f239f171b0911d7d42e4ce65bae9314b6
[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                 DoQUIT(CmdCtrlSocket);\r
1269                 DoClose(CmdCtrlSocket);\r
1270         }\r
1271 \r
1272         if(TrnCtrlSocket != INVALID_SOCKET)\r
1273         {\r
1274                 DoQUIT(TrnCtrlSocket);\r
1275                 DoClose(TrnCtrlSocket);\r
1276 \r
1277                 SaveCurrentSetToHistory();\r
1278 \r
1279                 EraseRemoteDirForWnd();\r
1280                 SetTaskMsg(MSGJPN004);\r
1281         }\r
1282 \r
1283         TrnCtrlSocket = INVALID_SOCKET;\r
1284         CmdCtrlSocket = INVALID_SOCKET;\r
1285 \r
1286         DispWindowTitle();\r
1287         MakeButtonsFocus();\r
1288         ClearBookMark();\r
1289 \r
1290         return;\r
1291 }\r
1292 \r
1293 \r
1294 /*----- ソケットが強制切断されたときの処理 ------------------------------------\r
1295 *\r
1296 *       Parameter\r
1297 *               なし\r
1298 *\r
1299 *       Return Value\r
1300 *               なし\r
1301 *----------------------------------------------------------------------------*/\r
1302 \r
1303 void DisconnectSet(void)\r
1304 {\r
1305         CmdCtrlSocket = INVALID_SOCKET;\r
1306         TrnCtrlSocket = INVALID_SOCKET;\r
1307 \r
1308         EraseRemoteDirForWnd();\r
1309         DispWindowTitle();\r
1310         MakeButtonsFocus();\r
1311         SetTaskMsg(MSGJPN005);\r
1312         return;\r
1313 }\r
1314 \r
1315 \r
1316 /*----- ホストに接続中かどうかを返す ------------------------------------------\r
1317 *\r
1318 *       Parameter\r
1319 *               なし\r
1320 *\r
1321 *       Return Value\r
1322 *               int ステータス (YES/NO)\r
1323 *----------------------------------------------------------------------------*/\r
1324 \r
1325 int AskConnecting(void)\r
1326 {\r
1327         int Sts;\r
1328 \r
1329         Sts = NO;\r
1330         if(TrnCtrlSocket != INVALID_SOCKET)\r
1331                 Sts = YES;\r
1332 \r
1333         return(Sts);\r
1334 }\r
1335 \r
1336 \r
1337 #if defined(HAVE_TANDEM)\r
1338 /*----- 接続している本当のホストのホストタイプを返す --------------------------\r
1339 *\r
1340 *       Parameter\r
1341 *               なし\r
1342 *\r
1343 *       Return Value\r
1344 *               char *ファイル名/オプション\r
1345 *----------------------------------------------------------------------------*/\r
1346 \r
1347 int AskRealHostType(void)\r
1348 {\r
1349         if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
1350                 CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
1351 \r
1352         return(CurHost.HostType);\r
1353 }\r
1354 \r
1355 /*----- OSS ファイルシステムにアクセスしているかどうかのフラグを変更する ------\r
1356 *\r
1357 *       Parameter\r
1358 *               int ステータス (YES/NO)\r
1359 *\r
1360 *       Return Value\r
1361 *               int ステータス (YES/NO)\r
1362 *----------------------------------------------------------------------------*/\r
1363 \r
1364 int SetOSS(int wkOss)\r
1365 {\r
1366         if(Oss != wkOss) {\r
1367                 if (wkOss == YES) {\r
1368                         strcpy(CurHost.InitCmd, "OSS");\r
1369                 } else {\r
1370                         strcpy(CurHost.InitCmd, "GUARDIAN");\r
1371                 }\r
1372         }\r
1373         Oss = wkOss;\r
1374         return(Oss);\r
1375 }\r
1376 \r
1377 /*----- OSS ファイルシステムにアクセスしているかどうかを返す ------------------\r
1378 *\r
1379 *       Parameter\r
1380 *               なし\r
1381 *\r
1382 *       Return Value\r
1383 *               int ステータス (YES/NO)\r
1384 *----------------------------------------------------------------------------*/\r
1385 \r
1386 int AskOSS(void)\r
1387 {\r
1388         return(Oss);\r
1389 }\r
1390 #endif /* HAVE_TANDEM */\r
1391 \r
1392 \r
1393 /*----- ホストへ接続する ------------------------------------------------------\r
1394 *\r
1395 *       Parameter\r
1396 *               char *Host : ホスト名\r
1397 *               char *User : ユーザ名\r
1398 *               char *Pass : パスワード\r
1399 *               char *Acct : アカウント\r
1400 *               int Port : ポート\r
1401 *               int Fwall : FireWallを使うかどうか (YES/NO)\r
1402 *               int SavePass : パスワードを再入力した時に保存するかどうか (YES/NO)\r
1403 *               int Security : セキュリティ (SECURITY_xxx, MDx)\r
1404 *\r
1405 *       Return Value\r
1406 *               SOCKET ソケット\r
1407 *\r
1408 *       Note\r
1409 *               ホスト名、ユーザ名、パスワードが指定されていなかったときは、接続に使用\r
1410 *               したものをコピーしてかえす\r
1411 *                       char *Host : ホスト名\r
1412 *                       char *User : ユーザ名\r
1413 *                       char *Pass : パスワード\r
1414 *                       char *Acct : アカウント\r
1415 *\r
1416 *               FireWallは次のように動作する\r
1417 *                       TYPE1   Connect fire → USER user(f) → PASS pass(f) → SITE host → USER user(h) →      PASS pass(h) → ACCT acct\r
1418 *                       TYPE2   Connect fire → USER user(f) → PASS pass(f) →              USER user(h)@host → PASS pass(h) → ACCT acct\r
1419 *                       TYPE3   Connect fire →                                              USER user(h)@host → PASS pass(h) → ACCT acct\r
1420 *                       TYPE4   Connect fire →                                 OPEN host → USER user(h) →      PASS pass(h) → ACCT acct\r
1421 *                       TYPE5   SOCKS4\r
1422 *                       none    Connect host →                                              USER user(h) →      PASS pass(h) → ACCT acct\r
1423 *----------------------------------------------------------------------------*/\r
1424 \r
1425 // 暗号化通信対応\r
1426 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
1427 {\r
1428         int Sts;\r
1429         int Flg;\r
1430         int Anony;\r
1431         SOCKET ContSock;\r
1432         char Buf[1024];\r
1433         char Reply[1024];\r
1434         int Continue;\r
1435         int ReInPass;\r
1436         char *Tmp;\r
1437         int HostPort;\r
1438         static const char *SiteTbl[4] = { "SITE", "site", "OPEN", "open" };\r
1439         char TmpBuf[ONELINE_BUF_SIZE];\r
1440         struct linger LingerOpt;\r
1441 \r
1442         // 暗号化通信対応\r
1443         ContSock = INVALID_SOCKET;\r
1444 \r
1445         if(CryptMode == CRYPT_NONE || CryptMode == CRYPT_FTPES || CryptMode == CRYPT_FTPIS)\r
1446         {\r
1447                 if(Fwall == YES)\r
1448                         Fwall = FwallType;\r
1449                 else\r
1450                         Fwall = FWALL_NONE;\r
1451 \r
1452                 TryConnect = YES;\r
1453                 // 暗号化通信対応\r
1454 //              CancelFlg = NO;\r
1455 #if 0\r
1456 //              WSASetBlockingHook(BlkHookFnc);\r
1457 #endif\r
1458 \r
1459                 ContSock = INVALID_SOCKET;\r
1460 \r
1461                 HostPort = Port;\r
1462                 Tmp = Host;\r
1463                 if(((Fwall >= FWALL_FU_FP_SITE) && (Fwall <= FWALL_OPEN)) ||\r
1464                    (Fwall == FWALL_SIDEWINDER) ||\r
1465                    (Fwall == FWALL_FU_FP))\r
1466                 {\r
1467                         Tmp = FwallHost;\r
1468                         Port = FwallPort;\r
1469                 }\r
1470 \r
1471                 if(strlen(Tmp) != 0)\r
1472                 {\r
1473                         // 同時接続対応\r
1474 //                      if((ContSock = connectsock(Tmp, Port, "", &CancelFlg)) != INVALID_SOCKET)\r
1475                         if((ContSock = connectsock(Tmp, Port, "", CancelCheckWork)) != INVALID_SOCKET)\r
1476                         {\r
1477                                 // バッファを無効\r
1478 #ifdef DISABLE_CONTROL_NETWORK_BUFFERS\r
1479                                 int BufferSize = 0;\r
1480                                 setsockopt(ContSock, SOL_SOCKET, SO_SNDBUF, (char*)&BufferSize, sizeof(int));\r
1481                                 setsockopt(ContSock, SOL_SOCKET, SO_RCVBUF, (char*)&BufferSize, sizeof(int));\r
1482 #endif\r
1483                                 // FTPIS対応\r
1484 //                              while((Sts = ReadReplyMessage(ContSock, Buf, 1024, &CancelFlg, TmpBuf) / 100) == FTP_PRELIM)\r
1485 //                                      ;\r
1486                                 if(CryptMode == CRYPT_FTPIS)\r
1487                                 {\r
1488                                         if(AttachSSL(ContSock, INVALID_SOCKET, CancelCheckWork))\r
1489                                         {\r
1490                                                 while((Sts = ReadReplyMessage(ContSock, Buf, 1024, CancelCheckWork, TmpBuf) / 100) == FTP_PRELIM)\r
1491                                                         ;\r
1492                                         }\r
1493                                         else\r
1494                                                 Sts = FTP_ERROR;\r
1495                                 }\r
1496                                 else\r
1497                                 {\r
1498                                         while((Sts = ReadReplyMessage(ContSock, Buf, 1024, CancelCheckWork, TmpBuf) / 100) == FTP_PRELIM)\r
1499                                                 ;\r
1500                                 }\r
1501 \r
1502                                 if(Sts == FTP_COMPLETE)\r
1503                                 {\r
1504                                         Flg = 1;\r
1505                                         if(setsockopt(ContSock, SOL_SOCKET, SO_OOBINLINE, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
1506                                                 ReportWSError("setsockopt", WSAGetLastError());\r
1507                                         // データ転送用ソケットのTCP遅延転送が無効されているので念のため\r
1508                                         if(setsockopt(ContSock, IPPROTO_TCP, TCP_NODELAY, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
1509                                                 ReportWSError("setsockopt", WSAGetLastError());\r
1510 //#pragma aaa\r
1511                                         Flg = 1;\r
1512                                         if(setsockopt(ContSock, SOL_SOCKET, SO_KEEPALIVE, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
1513                                                 ReportWSError("setsockopt", WSAGetLastError());\r
1514                                         LingerOpt.l_onoff = 1;\r
1515                                         LingerOpt.l_linger = 90;\r
1516                                         if(setsockopt(ContSock, SOL_SOCKET, SO_LINGER, (LPSTR)&LingerOpt, sizeof(LingerOpt)) == SOCKET_ERROR)\r
1517                                                 ReportWSError("setsockopt", WSAGetLastError());\r
1518 ///////\r
1519 \r
1520 \r
1521                                         /*===== 認証を行なう =====*/\r
1522 \r
1523                                         Sts = FTP_COMPLETE;\r
1524                                         if((Fwall == FWALL_FU_FP_SITE) ||\r
1525                                            (Fwall == FWALL_FU_FP_USER) ||\r
1526                                            (Fwall == FWALL_FU_FP))\r
1527                                         {\r
1528                                                 // 同時接続対応\r
1529 //                                              if((Sts = command(ContSock, Reply, &CancelFlg, "USER %s", FwallUser) / 100) == FTP_CONTINUE)\r
1530                                                 if((Sts = command(ContSock, Reply, CancelCheckWork, "USER %s", FwallUser) / 100) == FTP_CONTINUE)\r
1531                                                 {\r
1532                                                         CheckOneTimePassword(FwallPass, Reply, FwallSecurity);\r
1533                                                         // 同時接続対応\r
1534 //                                                      Sts = command(ContSock, NULL, &CancelFlg, "PASS %s", Reply) / 100;\r
1535                                                         Sts = command(ContSock, NULL, CancelCheckWork, "PASS %s", Reply) / 100;\r
1536                                                 }\r
1537                                         }\r
1538                                         else if(Fwall == FWALL_SIDEWINDER)\r
1539                                         {\r
1540                                                 // 同時接続対応\r
1541 //                                              Sts = command(ContSock, Reply, &CancelFlg, "USER %s:%s%c%s", FwallUser, FwallPass, FwallDelimiter, Host) / 100;\r
1542                                                 Sts = command(ContSock, Reply, CancelCheckWork, "USER %s:%s%c%s", FwallUser, FwallPass, FwallDelimiter, Host) / 100;\r
1543                                         }\r
1544                                         if((Sts != FTP_COMPLETE) && (Sts != FTP_CONTINUE))\r
1545                                         {\r
1546                                                 SetTaskMsg(MSGJPN006);\r
1547                                                 DoClose(ContSock);\r
1548                                                 ContSock = INVALID_SOCKET;\r
1549                                         }\r
1550                                         else\r
1551                                         {\r
1552                                                 if((Fwall == FWALL_FU_FP_SITE) || (Fwall == FWALL_OPEN))\r
1553                                                 {\r
1554                                                         Flg = 0;\r
1555                                                         if(Fwall == FWALL_OPEN)\r
1556                                                                 Flg = 2;\r
1557                                                         if(FwallLower == YES)\r
1558                                                                 Flg++;\r
1559 \r
1560                                                         if(HostPort == PORT_NOR)\r
1561                                                                 // 同時接続対応\r
1562 //                                                              Sts = command(ContSock, NULL, &CancelFlg, "%s %s", SiteTbl[Flg], Host) / 100;\r
1563                                                                 Sts = command(ContSock, NULL, CancelCheckWork, "%s %s", SiteTbl[Flg], Host) / 100;\r
1564                                                         else\r
1565                                                                 // 同時接続対応\r
1566 //                                                              Sts = command(ContSock, NULL, &CancelFlg, "%s %s %d", SiteTbl[Flg], Host, HostPort) / 100;\r
1567                                                                 Sts = command(ContSock, NULL, CancelCheckWork, "%s %s %d", SiteTbl[Flg], Host, HostPort) / 100;\r
1568                                                 }\r
1569 \r
1570                                                 if((Sts != FTP_COMPLETE) && (Sts != FTP_CONTINUE))\r
1571                                                 {\r
1572                                                         SetTaskMsg(MSGJPN007, Host);\r
1573                                                         DoClose(ContSock);\r
1574                                                         ContSock = INVALID_SOCKET;\r
1575                                                 }\r
1576                                                 else\r
1577                                                 {\r
1578                                                         Anony = NO;\r
1579                                                         // 同時接続対応\r
1580 //                                                      if((strlen(User) != 0) || \r
1581 //                                                         (InputDialogBox(username_dlg, GetMainHwnd(), NULL, User, USER_NAME_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
1582                                                         if((strlen(User) != 0) || \r
1583                                                            ((HostData->NoDisplayUI == NO) && (InputDialogBox(username_dlg, GetMainHwnd(), NULL, User, USER_NAME_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)))\r
1584                                                         {\r
1585                                                                 if(Anony == YES)\r
1586                                                                 {\r
1587                                                                         strcpy(User, "anonymous");\r
1588                                                                         strcpy(Pass, UserMailAdrs);\r
1589                                                                 }\r
1590 \r
1591                                                                 if((Fwall == FWALL_FU_FP_USER) || (Fwall == FWALL_USER))\r
1592                                                                 {\r
1593                                                                         if(HostPort == PORT_NOR)\r
1594                                                                                 sprintf(Buf, "%s%c%s", User, FwallDelimiter, Host);\r
1595                                                                         else\r
1596                                                                                 sprintf(Buf, "%s%c%s %d", User, FwallDelimiter, Host, HostPort);\r
1597                                                                 }\r
1598                                                                 else\r
1599                                                                         strcpy(Buf, User);\r
1600 \r
1601                                                                 // FTPES対応\r
1602                                                                 if(CryptMode == CRYPT_FTPES)\r
1603                                                                 {\r
1604                                                                         if(IsOpenSSLLoaded() && (Sts = command(ContSock, Reply, CancelCheckWork, "AUTH TLS")) == 234)\r
1605                                                                         {\r
1606                                                                                 if(AttachSSL(ContSock, INVALID_SOCKET, CancelCheckWork))\r
1607                                                                                 {\r
1608                                                                                         if((Sts = command(ContSock, Reply, CancelCheckWork, "PBSZ 0")) == 200)\r
1609                                                                                         {\r
1610                                                                                                 if((Sts = command(ContSock, Reply, CancelCheckWork, "PROT P")) == 200)\r
1611                                                                                                 {\r
1612                                                                                                 }\r
1613                                                                                                 else\r
1614                                                                                                         Sts = FTP_ERROR;\r
1615                                                                                         }\r
1616                                                                                         else\r
1617                                                                                                 Sts = FTP_ERROR;\r
1618                                                                                 }\r
1619                                                                                 else\r
1620                                                                                         Sts = FTP_ERROR;\r
1621                                                                         }\r
1622                                                                         else\r
1623                                                                                 Sts = FTP_ERROR;\r
1624                                                                 }\r
1625 \r
1626                                                                 // FTPIS対応\r
1627                                                                 // "PBSZ 0"と"PROT P"は黙示的に設定されているはずだが念のため\r
1628                                                                 if(CryptMode == CRYPT_FTPIS)\r
1629                                                                 {\r
1630                                                                         if((Sts = command(ContSock, Reply, CancelCheckWork, "PBSZ 0")) == 200)\r
1631                                                                         {\r
1632                                                                                 if((Sts = command(ContSock, Reply, CancelCheckWork, "PROT P")) == 200)\r
1633                                                                                 {\r
1634                                                                                 }\r
1635                                                                         }\r
1636                                                                 }\r
1637 \r
1638                                                                 ReInPass = NO;\r
1639                                                                 do\r
1640                                                                 {\r
1641                                                                         // FTPES対応\r
1642                                                                         if(Sts == FTP_ERROR)\r
1643                                                                                 break;\r
1644                                                                         Continue = NO;\r
1645                                                                         // 同時接続対応\r
1646 //                                                                      if((Sts = command(ContSock, Reply, &CancelFlg, "USER %s", Buf) / 100) == FTP_CONTINUE)\r
1647                                                                         if((Sts = command(ContSock, Reply, CancelCheckWork, "USER %s", Buf) / 100) == FTP_CONTINUE)\r
1648                                                                         {\r
1649                                                                                 // 同時接続対応\r
1650 //                                                                              if((strlen(Pass) != 0) || \r
1651 //                                                                                 (InputDialogBox(passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
1652                                                                                 if((strlen(Pass) != 0) || \r
1653                                                                                    ((HostData->NoDisplayUI == NO) && (InputDialogBox(passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)))\r
1654                                                                                 {\r
1655                                                                                         CheckOneTimePassword(Pass, Reply, Security);\r
1656 \r
1657                                                                                         /* パスワードがスペース1個の時はパスワードの実体なしとする */\r
1658                                                                                         if(strcmp(Reply, " ") == 0)\r
1659                                                                                                 strcpy(Reply, "");\r
1660 \r
1661                                                                                         // 同時接続対応\r
1662 //                                                                                      Sts = command(ContSock, NULL, &CancelFlg, "PASS %s", Reply) / 100;\r
1663                                                                                         Sts = command(ContSock, NULL, CancelCheckWork, "PASS %s", Reply) / 100;\r
1664                                                                                         if(Sts == FTP_ERROR)\r
1665                                                                                         {\r
1666                                                                                                 strcpy(Pass, "");\r
1667                                                                                                 // 同時接続対応\r
1668 //                                                                                              if(InputDialogBox(re_passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)\r
1669                                                                                                 if(HostData->NoDisplayUI == NO && InputDialogBox(re_passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)\r
1670                                                                                                         Continue = YES;\r
1671                                                                                                 else\r
1672                                                                                                         DoPrintf("No password specified.");\r
1673                                                                                                 ReInPass = YES;\r
1674                                                                                         }\r
1675                                                                                         else if(Sts == FTP_CONTINUE)\r
1676                                                                                         {\r
1677                                                                                                 // 同時接続対応\r
1678 //                                                                                              if((strlen(Acct) != 0) || \r
1679 //                                                                                                 (InputDialogBox(account_dlg, GetMainHwnd(), NULL, Acct, ACCOUNT_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
1680                                                                                                 if((strlen(Acct) != 0) || \r
1681                                                                                                    ((HostData->NoDisplayUI == NO) && (InputDialogBox(account_dlg, GetMainHwnd(), NULL, Acct, ACCOUNT_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)))\r
1682                                                                                                 {\r
1683                                                                                                         // 同時接続対応\r
1684 //                                                                                                      Sts = command(ContSock, NULL, &CancelFlg, "ACCT %s", Acct) / 100;\r
1685                                                                                                         Sts = command(ContSock, NULL, CancelCheckWork, "ACCT %s", Acct) / 100;\r
1686                                                                                                 }\r
1687                                                                                                 else\r
1688                                                                                                         DoPrintf("No account specified");\r
1689                                                                                         }\r
1690                                                                                 }\r
1691                                                                                 else\r
1692                                                                                 {\r
1693                                                                                         Sts = FTP_ERROR;\r
1694                                                                                         DoPrintf("No password specified.");\r
1695                                                                                 }\r
1696                                                                         }\r
1697                                                                         // FTPES対応\r
1698                                                                         if(Continue == YES)\r
1699                                                                                 Sts = FTP_COMPLETE;\r
1700                                                                 }\r
1701                                                                 while(Continue == YES);\r
1702                                                         }\r
1703                                                         else\r
1704                                                         {\r
1705                                                                 Sts = FTP_ERROR;\r
1706                                                                 DoPrintf("No user name specified");\r
1707                                                         }\r
1708 \r
1709                                                         if(Sts != FTP_COMPLETE)\r
1710                                                         {\r
1711                                                                 SetTaskMsg(MSGJPN008, Host);\r
1712                                                                 DoClose(ContSock);\r
1713                                                                 ContSock = INVALID_SOCKET;\r
1714                                                         }\r
1715                                                         else if((SavePass == YES) && (ReInPass == YES))\r
1716                                                         {\r
1717                                                                 // 同時接続対応\r
1718 //                                                              if(DialogBox(GetFtpInst(), MAKEINTRESOURCE(savepass_dlg), GetMainHwnd(), ExeEscDialogProc) == YES)\r
1719                                                                 if(HostData->NoDisplayUI == NO && DialogBox(GetFtpInst(), MAKEINTRESOURCE(savepass_dlg), GetMainHwnd(), ExeEscDialogProc) == YES)\r
1720                                                                         SetHostPassword(AskCurrentHost(), Pass);\r
1721                                                         }\r
1722                                                 }\r
1723                                         }\r
1724                                 }\r
1725                                 else\r
1726                                 {\r
1727 //#pragma aaa\r
1728                                         SetTaskMsg(MSGJPN009/*"接続できません(1) %x", ContSock*/);\r
1729                                         DoClose(ContSock);\r
1730                                         ContSock = INVALID_SOCKET;\r
1731                                 }\r
1732                         }\r
1733                 }\r
1734                 else\r
1735                 {\r
1736 \r
1737                         if(((Fwall >= FWALL_FU_FP_SITE) && (Fwall <= FWALL_OPEN)) ||\r
1738                            (Fwall == FWALL_FU_FP))\r
1739                                 SetTaskMsg(MSGJPN010);\r
1740                         else\r
1741                                 SetTaskMsg(MSGJPN011);\r
1742                 }\r
1743 \r
1744 #if 0\r
1745 //              WSAUnhookBlockingHook();\r
1746 #endif\r
1747                 TryConnect = NO;\r
1748 \r
1749                 // FEAT対応\r
1750                 // ホストの機能を確認\r
1751                 if(ContSock != INVALID_SOCKET)\r
1752                 {\r
1753                         if((Sts = command(ContSock, Reply, CancelCheckWork, "FEAT")) == 211)\r
1754                         {\r
1755                                 // 改行文字はReadReplyMessageで消去されるため区切り文字に空白を使用\r
1756                                 // UTF-8対応\r
1757                                 if(strstr(Reply, " UTF8 "))\r
1758                                         HostData->Feature |= FEATURE_UTF8;\r
1759                                 // MLST対応\r
1760                                 if(strstr(Reply, " MLST ") || strstr(Reply, " MLSD "))\r
1761                                         HostData->Feature |= FEATURE_MLSD;\r
1762                                 // IPv6対応\r
1763                                 if(strstr(Reply, " EPRT ") || strstr(Reply, " EPSV "))\r
1764                                         HostData->Feature |= FEATURE_EPRT | FEATURE_EPSV;\r
1765                         }\r
1766                         // UTF-8対応\r
1767                         if(HostData->CurNameKanjiCode == KANJI_AUTO && (HostData->Feature & FEATURE_UTF8))\r
1768                         {\r
1769                                 if((Sts = command(ContSock, Reply, CancelCheckWork, "OPTS UTF8 ON")) == 200)\r
1770                                         HostData->CurNameKanjiCode = KANJI_UTF8N;\r
1771                         }\r
1772                 }\r
1773         }\r
1774         else if(CryptMode == CRYPT_SFTP)\r
1775         {\r
1776                 // TODO:\r
1777                 // テストコード\r
1778                 // ログイン成功を確認\r
1779 #define strrcmp(_Str1, _Str2) (strcmp(strstr(_Str1, _Str2) ? strstr(_Str1, _Str2) : "", _Str2))\r
1780                 size_t r;\r
1781                 ContSock = SFTP_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);\r
1782                 SFTP_SetTimeoutCallback(ContSock, SSLTimeoutCallback);\r
1783                 while(1)\r
1784                 {\r
1785                         r = SFTP_recv(ContSock, Reply, 1024, 0);\r
1786                         if(r == SOCKET_ERROR)\r
1787                                 break;\r
1788                         if(r <= 0)\r
1789                                 continue;\r
1790                         Reply[r] = '\0';\r
1791                         SetTaskMsg("%s", Reply);\r
1792                         if(strrcmp(Reply, "psftp> ") == 0)\r
1793                                 break;\r
1794                 }\r
1795                 r = SFTP_send(ContSock, "open \"", strlen("open \""), 0);\r
1796                 r = SFTP_send(ContSock, Host, strlen(Host), 0);\r
1797                 r = SFTP_send(ContSock, "\"\r\n", strlen("\"\r\n"), 0);\r
1798                 while(1)\r
1799                 {\r
1800                         r = SFTP_recv(ContSock, Reply, 1024, 0);\r
1801                         if(r == SOCKET_ERROR)\r
1802                                 break;\r
1803                         if(r <= 0)\r
1804                                 continue;\r
1805                         Reply[r] = '\0';\r
1806                         SetTaskMsg("%s", Reply);\r
1807                         if(strrcmp(Reply, "Store key in cache? (y/n) ") == 0)\r
1808                         {\r
1809                                 r = SFTP_send(ContSock, "n\r\n", strlen("n\r\n"), 0);\r
1810                         }\r
1811                         if(strrcmp(Reply, "Update cached key? (y/n, Return cancels connection) ") == 0)\r
1812                         {\r
1813                                 r = SFTP_send(ContSock, "\r\n", strlen("\r\n"), 0);\r
1814                         }\r
1815                         if(strrcmp(Reply, "login as: ") == 0)\r
1816                         {\r
1817                                 r = SFTP_send(ContSock, User, strlen(User), 0);\r
1818                                 r = SFTP_send(ContSock, "\r\n", strlen("\r\n"), 0);\r
1819                         }\r
1820                         if(strrcmp(Reply, "password: ") == 0)\r
1821                         {\r
1822                                 r = SFTP_send(ContSock, Pass, strlen(Pass), 0);\r
1823                                 r = SFTP_send(ContSock, "\r\n", strlen("\r\n"), 0);\r
1824                         }\r
1825                         if(strrcmp(Reply, "psftp> ") == 0)\r
1826                                 break;\r
1827                         Sleep(1);\r
1828                 }\r
1829                 SFTP_closesocket(ContSock);\r
1830                 ContSock = INVALID_SOCKET;\r
1831         }\r
1832 \r
1833         return(ContSock);\r
1834 }\r
1835 \r
1836 // 同時接続対応\r
1837 //static SOCKET DoConnect(HOSTDATA* HostData, char *Host, char *User, char *Pass, char *Acct, int Port, int Fwall, int SavePass, int Security)\r
1838 static SOCKET DoConnect(HOSTDATA* HostData, char *Host, char *User, char *Pass, char *Acct, int Port, int Fwall, int SavePass, int Security, int *CancelCheckWork)\r
1839 {\r
1840         SOCKET ContSock;\r
1841         ContSock = INVALID_SOCKET;\r
1842         *CancelCheckWork = NO;\r
1843         if(*CancelCheckWork == NO && ContSock == INVALID_SOCKET && HostData->UseSFTP == YES)\r
1844         {\r
1845                 SetTaskMsg(MSGJPN317);\r
1846                 if((ContSock = DoConnectCrypt(CRYPT_SFTP, HostData, Host, User, Pass, Acct, Port, Fwall, SavePass, Security, CancelCheckWork)) != INVALID_SOCKET)\r
1847                         HostData->CryptMode = CRYPT_SFTP;\r
1848         }\r
1849         if(*CancelCheckWork == NO && ContSock == INVALID_SOCKET && HostData->UseFTPIS == YES)\r
1850         {\r
1851                 SetTaskMsg(MSGJPN316);\r
1852                 if((ContSock = DoConnectCrypt(CRYPT_FTPIS, HostData, Host, User, Pass, Acct, Port, Fwall, SavePass, Security, CancelCheckWork)) != INVALID_SOCKET)\r
1853                         HostData->CryptMode = CRYPT_FTPIS;\r
1854         }\r
1855         if(*CancelCheckWork == NO && ContSock == INVALID_SOCKET && HostData->UseFTPES == YES)\r
1856         {\r
1857                 SetTaskMsg(MSGJPN315);\r
1858                 if((ContSock = DoConnectCrypt(CRYPT_FTPES, HostData, Host, User, Pass, Acct, Port, Fwall, SavePass, Security, CancelCheckWork)) != INVALID_SOCKET)\r
1859                         HostData->CryptMode = CRYPT_FTPES;\r
1860         }\r
1861         if(*CancelCheckWork == NO && ContSock == INVALID_SOCKET && HostData->UseNoEncryption == YES)\r
1862         {\r
1863                 SetTaskMsg(MSGJPN314);\r
1864                 if((ContSock = DoConnectCrypt(CRYPT_NONE, HostData, Host, User, Pass, Acct, Port, Fwall, SavePass, Security, CancelCheckWork)) != INVALID_SOCKET)\r
1865                         HostData->CryptMode = CRYPT_NONE;\r
1866         }\r
1867         return ContSock;\r
1868 }\r
1869 \r
1870 \r
1871 /*----- ワンタイムパスワードのチェック ----------------------------------------\r
1872 *\r
1873 *       Parameter\r
1874 *               chat *Pass : パスワード/パスフレーズ\r
1875 *               char *Reply : USERコマンドを送ったあとのリプライ文字列\r
1876 *                                               /PASSコマンドで送るパスワードを返すバッファ\r
1877 *               int Type : タイプ (SECURITY_xxx, MDx)\r
1878 *\r
1879 *       Return Value\r
1880 *               int ステータス\r
1881 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
1882 *\r
1883 *       Note\r
1884 *               ワンタイムパスワードでない時はPassをそのままReplyにコピー\r
1885 *----------------------------------------------------------------------------*/\r
1886 \r
1887 static int CheckOneTimePassword(char *Pass, char *Reply, int Type)\r
1888 {\r
1889         int Sts;\r
1890         char *Pos;\r
1891         int Seq;\r
1892         char Seed[MAX_SEED_LEN+1];\r
1893         int i;\r
1894 \r
1895         Sts = FFFTP_SUCCESS;\r
1896         Pos = NULL;\r
1897 \r
1898         if(Type == SECURITY_AUTO)\r
1899         {\r
1900                 if((Pos = stristr(Reply, "otp-md5")) != NULL)\r
1901                 {\r
1902                         Type = MD5;\r
1903                         SetTaskMsg(MSGJPN012);\r
1904                 }\r
1905                 else if((Pos = stristr(Reply, "otp-sha1")) != NULL)\r
1906                 {\r
1907                         Type = SHA1;\r
1908                         SetTaskMsg(MSGJPN013);\r
1909                 }\r
1910                 else if(((Pos = stristr(Reply, "otp-md4")) != NULL) || ((Pos = stristr(Reply, "s/key")) != NULL))\r
1911                 {\r
1912                         Type = MD4;\r
1913                         SetTaskMsg(MSGJPN014);\r
1914                 }\r
1915         }\r
1916         else\r
1917                 Pos = GetNextField(Reply);\r
1918 \r
1919         if((Type == MD4) || (Type == MD5) || (Type == SHA1))\r
1920         {\r
1921                 /* シーケンス番号を見つけるループ */\r
1922                 DoPrintf("Analize OTP");\r
1923                 DoPrintf("%s", Pos);\r
1924                 Sts = FFFTP_FAIL;\r
1925                 while((Pos = GetNextField(Pos)) != NULL)\r
1926                 {\r
1927                         if(IsDigit(*Pos))\r
1928                         {\r
1929                                 Seq = atoi(Pos);\r
1930                                 DoPrintf("Sequence=%d", Seq);\r
1931 \r
1932                                 /* Seed */\r
1933                                 if((Pos = GetNextField(Pos)) != NULL)\r
1934                                 {\r
1935                                         if(GetOneField(Pos, Seed, MAX_SEED_LEN) == FFFTP_SUCCESS)\r
1936                                         {\r
1937                                                 /* Seedは英数字のみ有効とする */\r
1938                                                 for(i = strlen(Seed)-1; i >= 0; i--)\r
1939                                                 {\r
1940                                                         if((IsAlpha(Seed[i]) == 0) && (IsDigit(Seed[i]) == 0))\r
1941                                                                 Seed[i] = NUL;\r
1942                                                 }\r
1943                                                 if(strlen(Seed) > 0)\r
1944                                                 {\r
1945                                                         DoPrintf("Seed=%s", Seed);\r
1946                                                         Make6WordPass(Seq, Seed, Pass, Type, Reply);\r
1947                                                         DoPrintf("Response=%s", Reply);\r
1948 \r
1949                                                         /* シーケンス番号のチェックと警告 */\r
1950                                                         if(Seq <= 10)\r
1951                                                                 DialogBox(GetFtpInst(), MAKEINTRESOURCE(otp_notify_dlg), GetMainHwnd(), ExeEscDialogProc);\r
1952 \r
1953                                                         Sts = FFFTP_SUCCESS;\r
1954                                                 }\r
1955                                         }\r
1956                                 }\r
1957                                 break;\r
1958                         }\r
1959                 }\r
1960 \r
1961                 if(Sts == FFFTP_FAIL)\r
1962                         SetTaskMsg(MSGJPN015);\r
1963         }\r
1964         else\r
1965         {\r
1966                 strcpy(Reply, Pass);\r
1967                 DoPrintf("No OTP used.");\r
1968         }\r
1969         return(Sts);\r
1970 }\r
1971 \r
1972 \r
1973 \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 *       Parameter\r
1988 *               char *host : ホスト名\r
1989 *               int port : ポート番号\r
1990 *               char *PreMsg : メッセージの前半部分\r
1991 *\r
1992 *       Return Value\r
1993 *               SOCKET ソケット\r
1994 *----------------------------------------------------------------------------*/\r
1995 \r
1996 // IPv6対応\r
1997 SOCKET connectsock(char *host, int port, char *PreMsg, int *CancelCheckWork)\r
1998 {\r
1999         SOCKET Result;\r
2000         Result = INVALID_SOCKET;\r
2001         switch(CurHost.CurNetType)\r
2002         {\r
2003         case NTYPE_AUTO:\r
2004                 if((Result = connectsockIPv4(host, port, PreMsg, CancelCheckWork)) != INVALID_SOCKET)\r
2005                         CurHost.CurNetType = NTYPE_IPV4;\r
2006                 else if((Result = connectsockIPv6(host, port, PreMsg, CancelCheckWork)) != INVALID_SOCKET)\r
2007                         CurHost.CurNetType = NTYPE_IPV6;\r
2008                 break;\r
2009         case NTYPE_IPV4:\r
2010                 Result = connectsockIPv4(host, port, PreMsg, CancelCheckWork);\r
2011                 CurHost.CurNetType = NTYPE_IPV4;\r
2012                 break;\r
2013         case NTYPE_IPV6:\r
2014                 Result = connectsockIPv6(host, port, PreMsg, CancelCheckWork);\r
2015                 CurHost.CurNetType = NTYPE_IPV6;\r
2016                 break;\r
2017         }\r
2018         return Result;\r
2019 }\r
2020 \r
2021 \r
2022 // IPv6対応\r
2023 //SOCKET connectsock(char *host, int port, char *PreMsg, int *CancelCheckWork)\r
2024 SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork)\r
2025 {\r
2026         struct sockaddr_in saSockAddr;\r
2027         char HostEntry[MAXGETHOSTSTRUCT];\r
2028         struct hostent *pHostEntry;\r
2029         SOCKET sSocket;\r
2030         int Len;\r
2031         int Fwall;\r
2032         SOCKS4CMD Socks4Cmd;\r
2033         SOCKS4REPLY Socks4Reply;\r
2034         SOCKS5REQUEST Socks5Cmd;\r
2035         SOCKS5REPLY Socks5Reply;\r
2036 \r
2037         //////////////////////////////\r
2038         // ホスト名解決と接続の準備\r
2039         //////////////////////////////\r
2040 \r
2041         Fwall = FWALL_NONE;\r
2042         if(AskHostFireWall() == YES)\r
2043                 Fwall = FwallType;\r
2044 \r
2045         sSocket = INVALID_SOCKET;\r
2046 \r
2047         UseIPadrs = YES;\r
2048         strcpy(DomainName, host);\r
2049         // IPv6対応\r
2050 //      memset(&CurSockAddr, 0, sizeof(CurSockAddr));\r
2051 //      CurSockAddr.sin_port = htons((u_short)port);\r
2052 //      CurSockAddr.sin_family = AF_INET;\r
2053 //      if((CurSockAddr.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE)\r
2054         memset(&CurSockAddrIPv4, 0, sizeof(CurSockAddrIPv4));\r
2055         CurSockAddrIPv4.sin_port = htons((u_short)port);\r
2056         CurSockAddrIPv4.sin_family = AF_INET;\r
2057         if((CurSockAddrIPv4.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE)\r
2058         {\r
2059                 // ホスト名が指定された\r
2060                 // ホスト名からアドレスを求める\r
2061                 if(((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER)) &&\r
2062                    (FwallResolv == YES))\r
2063                 {\r
2064                         // ホスト名解決はSOCKSサーバに任せる\r
2065                         pHostEntry = NULL;\r
2066                 }\r
2067                 else\r
2068                 {\r
2069                         // アドレスを取得\r
2070                         SetTaskMsg(MSGJPN016, DomainName);\r
2071                         // IPv6対応\r
2072 //                      pHostEntry = do_gethostbyname(host, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork);\r
2073                         pHostEntry = do_gethostbynameIPv4(host, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork);\r
2074                 }\r
2075 \r
2076                 if(pHostEntry != NULL)\r
2077                 {\r
2078                         // IPv6対応\r
2079 //                      memcpy((char *)&CurSockAddr.sin_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
2080 //                      SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet_ntoa(CurSockAddr.sin_addr), ntohs(CurSockAddr.sin_port));\r
2081                         memcpy((char *)&CurSockAddrIPv4.sin_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
2082                         SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet_ntoa(CurSockAddrIPv4.sin_addr), ntohs(CurSockAddrIPv4.sin_port));\r
2083                 }\r
2084                 else\r
2085                 {\r
2086                         if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2087                         {\r
2088                                 UseIPadrs = NO;\r
2089                                 // IPv6対応\r
2090 //                              SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddr.sin_port));\r
2091                                 SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddrIPv4.sin_port));\r
2092                         }\r
2093                         else\r
2094                         {\r
2095                                 SetTaskMsg(MSGJPN019, host);\r
2096                                 return(INVALID_SOCKET);\r
2097                         }\r
2098                 }\r
2099         }\r
2100         else\r
2101                 // IPv6対応\r
2102 //              SetTaskMsg(MSGJPN020, PreMsg, inet_ntoa(CurSockAddr.sin_addr), ntohs(CurSockAddr.sin_port));\r
2103                 SetTaskMsg(MSGJPN020, PreMsg, inet_ntoa(CurSockAddrIPv4.sin_addr), ntohs(CurSockAddrIPv4.sin_port));\r
2104 \r
2105         if((Fwall == FWALL_SOCKS4) || (Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2106         {\r
2107                 // SOCKSを使う\r
2108                 // SOCKSに接続する準備\r
2109                 if(Fwall == FWALL_SOCKS4)\r
2110                 {\r
2111                         Socks4Cmd.Ver = SOCKS4_VER;\r
2112                         Socks4Cmd.Cmd = SOCKS4_CMD_CONNECT;\r
2113                         // IPv6対応\r
2114 //                      Socks4Cmd.Port = CurSockAddr.sin_port;\r
2115 //                      Socks4Cmd.AdrsInt = CurSockAddr.sin_addr.s_addr;\r
2116                         Socks4Cmd.Port = CurSockAddrIPv4.sin_port;\r
2117                         Socks4Cmd.AdrsInt = CurSockAddrIPv4.sin_addr.s_addr;\r
2118                         strcpy(Socks4Cmd.UserID, FwallUser);\r
2119                         Len = offsetof(SOCKS4CMD, UserID) + strlen(FwallUser) + 1;\r
2120                 }\r
2121                 else\r
2122                 {\r
2123                         // IPv6対応\r
2124 //                      Len = Socks5MakeCmdPacket(&Socks5Cmd, SOCKS5_CMD_CONNECT, UseIPadrs, CurSockAddr.sin_addr.s_addr, DomainName, CurSockAddr.sin_port);\r
2125                         Len = Socks5MakeCmdPacket(&Socks5Cmd, SOCKS5_CMD_CONNECT, UseIPadrs, CurSockAddrIPv4.sin_addr.s_addr, DomainName, CurSockAddrIPv4.sin_port);\r
2126                 }\r
2127 \r
2128                 // IPv6対応\r
2129 //              memset(&SocksSockAddr, 0, sizeof(SocksSockAddr));\r
2130 //              if((SocksSockAddr.sin_addr.s_addr = inet_addr(FwallHost)) == INADDR_NONE)\r
2131                 memset(&SocksSockAddrIPv4, 0, sizeof(SocksSockAddrIPv4));\r
2132                 if((SocksSockAddrIPv4.sin_addr.s_addr = inet_addr(FwallHost)) == INADDR_NONE)\r
2133                 {\r
2134                         // IPv6対応\r
2135 //                      if((pHostEntry = do_gethostbyname(FwallHost, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork)) != NULL)\r
2136 //                              memcpy((char *)&SocksSockAddr.sin_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
2137                         if((pHostEntry = do_gethostbynameIPv4(FwallHost, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork)) != NULL)\r
2138                                 memcpy((char *)&SocksSockAddrIPv4.sin_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
2139                         else\r
2140                         {\r
2141                                 SetTaskMsg(MSGJPN021, FwallHost);\r
2142                                 return INVALID_SOCKET;\r
2143                         }\r
2144                 }\r
2145                 // IPv6対応\r
2146 //              SocksSockAddr.sin_port = htons((u_short)FwallPort);\r
2147 //              SocksSockAddr.sin_family = AF_INET;\r
2148 //              SetTaskMsg(MSGJPN022, inet_ntoa(SocksSockAddr.sin_addr), ntohs(SocksSockAddr.sin_port));\r
2149                 SocksSockAddrIPv4.sin_port = htons((u_short)FwallPort);\r
2150                 SocksSockAddrIPv4.sin_family = AF_INET;\r
2151                 SetTaskMsg(MSGJPN022, inet_ntoa(SocksSockAddrIPv4.sin_addr), ntohs(SocksSockAddrIPv4.sin_port));\r
2152                 // connectで接続する先はSOCKSサーバ\r
2153                 // IPv6対応\r
2154 //              memcpy(&saSockAddr, &SocksSockAddr, sizeof(SocksSockAddr));\r
2155                 memcpy(&saSockAddr, &SocksSockAddrIPv4, sizeof(SocksSockAddrIPv4));\r
2156         }\r
2157         else\r
2158         {\r
2159                 // connectで接続するのは接続先のホスト\r
2160                 // IPv6対応\r
2161 //              memcpy(&saSockAddr, &CurSockAddr, sizeof(CurSockAddr));\r
2162                 memcpy(&saSockAddr, &CurSockAddrIPv4, sizeof(CurSockAddrIPv4));\r
2163         }\r
2164 \r
2165         /////////////\r
2166         // 接続実行\r
2167         /////////////\r
2168 \r
2169         if((sSocket = do_socket(AF_INET, SOCK_STREAM, TCP_PORT)) != INVALID_SOCKET)\r
2170         {\r
2171                 if(do_connect(sSocket, (struct sockaddr *)&saSockAddr, sizeof(saSockAddr), CancelCheckWork) != SOCKET_ERROR)\r
2172                 {\r
2173                         if(Fwall == FWALL_SOCKS4)\r
2174                         {\r
2175                                 Socks4Reply.Result = -1;\r
2176                                 // 同時接続対応\r
2177 //                              if((SocksSendCmd(sSocket, &Socks4Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2178 //                                 (Socks4GetCmdReply(sSocket, &Socks4Reply) != FFFTP_SUCCESS) || \r
2179 //                                 (Socks4Reply.Result != SOCKS4_RES_OK))\r
2180                                 if((SocksSendCmd(sSocket, &Socks4Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2181                                    (Socks4GetCmdReply(sSocket, &Socks4Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
2182                                    (Socks4Reply.Result != SOCKS4_RES_OK))\r
2183                                 {\r
2184                                         SetTaskMsg(MSGJPN023, Socks4Reply.Result);\r
2185                                         DoClose(sSocket);\r
2186                                         sSocket = INVALID_SOCKET;\r
2187                                 }\r
2188                         }\r
2189                         else if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2190                         {\r
2191                                 if(Socks5SelMethod(sSocket, CancelCheckWork) == FFFTP_FAIL)\r
2192                                 {\r
2193                                         DoClose(sSocket);\r
2194                                         sSocket = INVALID_SOCKET;\r
2195                                 }\r
2196 \r
2197                                 Socks5Reply.Result = -1;\r
2198                                 // 同時接続対応\r
2199 //                              if((SocksSendCmd(sSocket, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2200 //                                 (Socks5GetCmdReply(sSocket, &Socks5Reply) != FFFTP_SUCCESS) || \r
2201 //                                 (Socks5Reply.Result != SOCKS5_RES_OK))\r
2202                                 if((SocksSendCmd(sSocket, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2203                                    (Socks5GetCmdReply(sSocket, &Socks5Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
2204                                    (Socks5Reply.Result != SOCKS5_RES_OK))\r
2205                                 {\r
2206                                         SetTaskMsg(MSGJPN024, Socks5Reply.Result);\r
2207                                         DoClose(sSocket);\r
2208                                         sSocket = INVALID_SOCKET;\r
2209                                 }\r
2210 \r
2211                         }\r
2212 \r
2213                         if(sSocket != INVALID_SOCKET)\r
2214                                 SetTaskMsg(MSGJPN025);\r
2215                 }\r
2216                 else\r
2217                 {\r
2218 //#pragma aaa\r
2219                         SetTaskMsg(MSGJPN026/*"接続できません(2) %x", sSocket*/);\r
2220                         DoClose(sSocket);\r
2221                         sSocket = INVALID_SOCKET;\r
2222                 }\r
2223         }\r
2224         else\r
2225                 SetTaskMsg(MSGJPN027);\r
2226 \r
2227         return(sSocket);\r
2228 }\r
2229 \r
2230 \r
2231 SOCKET connectsockIPv6(char *host, int port, char *PreMsg, int *CancelCheckWork)\r
2232 {\r
2233         struct sockaddr_in6 saSockAddr;\r
2234         char HostEntry[MAXGETHOSTSTRUCT];\r
2235         struct hostent *pHostEntry;\r
2236         SOCKET sSocket;\r
2237         int Len;\r
2238         int Fwall;\r
2239         SOCKS5REQUEST Socks5Cmd;\r
2240         SOCKS5REPLY Socks5Reply;\r
2241 \r
2242         //////////////////////////////\r
2243         // ホスト名解決と接続の準備\r
2244         //////////////////////////////\r
2245 \r
2246         Fwall = FWALL_NONE;\r
2247         if(AskHostFireWall() == YES)\r
2248                 Fwall = FwallType;\r
2249 \r
2250         sSocket = INVALID_SOCKET;\r
2251 \r
2252         UseIPadrs = YES;\r
2253         strcpy(DomainName, host);\r
2254         memset(&CurSockAddrIPv6, 0, sizeof(CurSockAddrIPv6));\r
2255         CurSockAddrIPv6.sin6_port = htons((u_short)port);\r
2256         CurSockAddrIPv6.sin6_family = AF_INET6;\r
2257         CurSockAddrIPv6.sin6_addr = inet6_addr(host);\r
2258         if(memcmp(&CurSockAddrIPv6.sin6_addr, &IN6ADDR_NONE, sizeof(struct in6_addr)) == 0)\r
2259         {\r
2260                 // ホスト名が指定された\r
2261                 // ホスト名からアドレスを求める\r
2262                 if(((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER)) &&\r
2263                    (FwallResolv == YES))\r
2264                 {\r
2265                         // ホスト名解決はSOCKSサーバに任せる\r
2266                         pHostEntry = NULL;\r
2267                 }\r
2268                 else\r
2269                 {\r
2270                         // アドレスを取得\r
2271                         SetTaskMsg(MSGJPN016, DomainName);\r
2272                         pHostEntry = do_gethostbynameIPv6(host, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork);\r
2273                 }\r
2274 \r
2275                 if(pHostEntry != NULL)\r
2276                 {\r
2277                         memcpy((char *)&CurSockAddrIPv6.sin6_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
2278                         SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet6_ntoa(CurSockAddrIPv6.sin6_addr), ntohs(CurSockAddrIPv6.sin6_port));\r
2279                 }\r
2280                 else\r
2281                 {\r
2282                         if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2283                         {\r
2284                                 UseIPadrs = NO;\r
2285                                 SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddrIPv6.sin6_port));\r
2286                         }\r
2287                         else\r
2288                         {\r
2289                                 SetTaskMsg(MSGJPN019, host);\r
2290                                 return(INVALID_SOCKET);\r
2291                         }\r
2292                 }\r
2293         }\r
2294         else\r
2295                 SetTaskMsg(MSGJPN020, PreMsg, inet6_ntoa(CurSockAddrIPv6.sin6_addr), ntohs(CurSockAddrIPv6.sin6_port));\r
2296 \r
2297         if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2298         {\r
2299                 // SOCKSを使う\r
2300                 // SOCKSに接続する準備\r
2301                 {\r
2302                         Len = Socks5MakeCmdPacketIPv6(&Socks5Cmd, SOCKS5_CMD_CONNECT, UseIPadrs, (char*)&CurSockAddrIPv6.sin6_addr, DomainName, CurSockAddrIPv6.sin6_port);\r
2303                 }\r
2304 \r
2305                 memset(&SocksSockAddrIPv6, 0, sizeof(SocksSockAddrIPv6));\r
2306                 SocksSockAddrIPv6.sin6_addr = inet6_addr(FwallHost);\r
2307                 if(memcmp(&SocksSockAddrIPv6.sin6_addr, &IN6ADDR_NONE, sizeof(struct in6_addr)) == 0)\r
2308                 {\r
2309                         if((pHostEntry = do_gethostbynameIPv6(FwallHost, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork)) != NULL)\r
2310                                 memcpy((char *)&SocksSockAddrIPv6.sin6_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
2311                         else\r
2312                         {\r
2313                                 SetTaskMsg(MSGJPN021, FwallHost);\r
2314                                 return INVALID_SOCKET;\r
2315                         }\r
2316                 }\r
2317                 SocksSockAddrIPv6.sin6_port = htons((u_short)FwallPort);\r
2318                 SocksSockAddrIPv6.sin6_family = AF_INET6;\r
2319                 SetTaskMsg(MSGJPN022, inet6_ntoa(SocksSockAddrIPv6.sin6_addr), ntohs(SocksSockAddrIPv6.sin6_port));\r
2320                 // connectで接続する先はSOCKSサーバ\r
2321                 memcpy(&saSockAddr, &SocksSockAddrIPv6, sizeof(SocksSockAddrIPv6));\r
2322         }\r
2323         else\r
2324         {\r
2325                 // connectで接続するのは接続先のホスト\r
2326                 memcpy(&saSockAddr, &CurSockAddrIPv6, sizeof(CurSockAddrIPv6));\r
2327         }\r
2328 \r
2329         /////////////\r
2330         // 接続実行\r
2331         /////////////\r
2332 \r
2333         inet6_ntoa(saSockAddr.sin6_addr);\r
2334         if((sSocket = do_socket(AF_INET6, SOCK_STREAM, TCP_PORT)) != INVALID_SOCKET)\r
2335         {\r
2336                 if(do_connect(sSocket, (struct sockaddr *)&saSockAddr, sizeof(saSockAddr), CancelCheckWork) != SOCKET_ERROR)\r
2337                 {\r
2338                         if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2339                         {\r
2340                                 if(Socks5SelMethod(sSocket, CancelCheckWork) == FFFTP_FAIL)\r
2341                                 {\r
2342                                         DoClose(sSocket);\r
2343                                         sSocket = INVALID_SOCKET;\r
2344                                 }\r
2345 \r
2346                                 Socks5Reply.Result = -1;\r
2347                                 // 同時接続対応\r
2348 //                              if((SocksSendCmd(sSocket, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2349 //                                 (Socks5GetCmdReply(sSocket, &Socks5Reply) != FFFTP_SUCCESS) || \r
2350 //                                 (Socks5Reply.Result != SOCKS5_RES_OK))\r
2351                                 if((SocksSendCmd(sSocket, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2352                                    (Socks5GetCmdReply(sSocket, &Socks5Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
2353                                    (Socks5Reply.Result != SOCKS5_RES_OK))\r
2354                                 {\r
2355                                         SetTaskMsg(MSGJPN024, Socks5Reply.Result);\r
2356                                         DoClose(sSocket);\r
2357                                         sSocket = INVALID_SOCKET;\r
2358                                 }\r
2359 \r
2360                         }\r
2361 \r
2362                         if(sSocket != INVALID_SOCKET)\r
2363                                 SetTaskMsg(MSGJPN025);\r
2364                 }\r
2365                 else\r
2366                 {\r
2367 //#pragma aaa\r
2368                         SetTaskMsg(MSGJPN026/*"接続できません(2) %x", sSocket*/);\r
2369                         DoClose(sSocket);\r
2370                         sSocket = INVALID_SOCKET;\r
2371                 }\r
2372         }\r
2373         else\r
2374                 SetTaskMsg(MSGJPN027);\r
2375 \r
2376         return(sSocket);\r
2377 }\r
2378 \r
2379 \r
2380 /*----- リッスンソケットを取得 ------------------------------------------------\r
2381 *\r
2382 *       Parameter\r
2383 *               SOCKET ctrl_skt : コントロールソケット\r
2384 *\r
2385 *       Return Value\r
2386 *               SOCKET リッスンソケット\r
2387 *----------------------------------------------------------------------------*/\r
2388 \r
2389 // IPv6対応\r
2390 SOCKET GetFTPListenSocket(SOCKET ctrl_skt, int *CancelCheckWork)\r
2391 {\r
2392         SOCKET Result;\r
2393         Result = INVALID_SOCKET;\r
2394         switch(CurHost.CurNetType)\r
2395         {\r
2396         case NTYPE_IPV4:\r
2397                 Result = GetFTPListenSocketIPv4(ctrl_skt, CancelCheckWork);\r
2398                 break;\r
2399         case NTYPE_IPV6:\r
2400                 Result = GetFTPListenSocketIPv6(ctrl_skt, CancelCheckWork);\r
2401                 break;\r
2402         }\r
2403         return Result;\r
2404 }\r
2405 \r
2406 \r
2407 // IPv6対応\r
2408 //SOCKET GetFTPListenSocket(SOCKET ctrl_skt, int *CancelCheckWork)\r
2409 SOCKET GetFTPListenSocketIPv4(SOCKET ctrl_skt, int *CancelCheckWork)\r
2410 {\r
2411     SOCKET listen_skt;\r
2412     int iLength;\r
2413     char *a,*p;\r
2414         struct sockaddr_in saCtrlAddr;\r
2415         struct sockaddr_in saTmpAddr;\r
2416         SOCKS4CMD Socks4Cmd;\r
2417         SOCKS4REPLY Socks4Reply;\r
2418         SOCKS5REQUEST Socks5Cmd;\r
2419         SOCKS5REPLY Socks5Reply;\r
2420 \r
2421         int Len;\r
2422         int Fwall;\r
2423 \r
2424         Fwall = FWALL_NONE;\r
2425         if(AskHostFireWall() == YES)\r
2426                 Fwall = FwallType;\r
2427 \r
2428         if((listen_skt = do_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) != INVALID_SOCKET)\r
2429         {\r
2430                 if(Fwall == FWALL_SOCKS4)\r
2431                 {\r
2432                         /*===== SOCKS4を使う =====*/\r
2433                         DoPrintf("Use SOCKS4 BIND");\r
2434                         // IPv6対応\r
2435 //                      if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddr, sizeof(SocksSockAddr), CancelCheckWork) != SOCKET_ERROR)\r
2436                         if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddrIPv4, sizeof(SocksSockAddrIPv4), CancelCheckWork) != SOCKET_ERROR)\r
2437                         {\r
2438                                 Socks4Cmd.Ver = SOCKS4_VER;\r
2439                                 Socks4Cmd.Cmd = SOCKS4_CMD_BIND;\r
2440                                 // IPv6対応\r
2441 //                              Socks4Cmd.Port = CurSockAddr.sin_port;\r
2442 //                              Socks4Cmd.AdrsInt = CurSockAddr.sin_addr.s_addr;\r
2443                                 Socks4Cmd.Port = CurSockAddrIPv4.sin_port;\r
2444                                 Socks4Cmd.AdrsInt = CurSockAddrIPv4.sin_addr.s_addr;\r
2445                                 strcpy(Socks4Cmd.UserID, FwallUser);\r
2446                                 Len = offsetof(SOCKS4CMD, UserID) + strlen(FwallUser) + 1;\r
2447 \r
2448                                 Socks4Reply.Result = -1;\r
2449                                 // 同時接続対応\r
2450 //                              if((SocksSendCmd(listen_skt, &Socks4Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2451 //                                 (Socks4GetCmdReply(listen_skt, &Socks4Reply) != FFFTP_SUCCESS) || \r
2452 //                                 (Socks4Reply.Result != SOCKS4_RES_OK))\r
2453                                 if((SocksSendCmd(listen_skt, &Socks4Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2454                                    (Socks4GetCmdReply(listen_skt, &Socks4Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
2455                                    (Socks4Reply.Result != SOCKS4_RES_OK))\r
2456                                 {\r
2457                                         SetTaskMsg(MSGJPN028, Socks4Reply.Result);\r
2458                                         DoClose(listen_skt);\r
2459                                         listen_skt = INVALID_SOCKET;\r
2460                                 }\r
2461 \r
2462                                 if(Socks4Reply.AdrsInt == 0)\r
2463                                         // IPv6対応\r
2464 //                                      Socks4Reply.AdrsInt = SocksSockAddr.sin_addr.s_addr;\r
2465                                         Socks4Reply.AdrsInt = SocksSockAddrIPv4.sin_addr.s_addr;\r
2466 \r
2467                                 a = (char *)&Socks4Reply.AdrsInt;\r
2468                                 p = (char *)&Socks4Reply.Port;\r
2469                         }\r
2470                 }\r
2471                 else if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2472                 {\r
2473                         /*===== SOCKS5を使う =====*/\r
2474                         DoPrintf("Use SOCKS5 BIND");\r
2475                         // IPv6対応\r
2476 //                      if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddr, sizeof(SocksSockAddr), CancelCheckWork) != SOCKET_ERROR)\r
2477                         if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddrIPv4, sizeof(SocksSockAddrIPv4), CancelCheckWork) != SOCKET_ERROR)\r
2478                         {\r
2479                                 if(Socks5SelMethod(listen_skt, CancelCheckWork) == FFFTP_FAIL)\r
2480                                 {\r
2481                                         DoClose(listen_skt);\r
2482                                         listen_skt = INVALID_SOCKET;\r
2483                                         return(listen_skt);\r
2484                                 }\r
2485 \r
2486                                 // IPv6対応\r
2487 //                              Len = Socks5MakeCmdPacket(&Socks5Cmd, SOCKS5_CMD_BIND, UseIPadrs, CurSockAddr.sin_addr.s_addr, DomainName, CurSockAddr.sin_port);\r
2488                                 Len = Socks5MakeCmdPacket(&Socks5Cmd, SOCKS5_CMD_BIND, UseIPadrs, CurSockAddrIPv4.sin_addr.s_addr, DomainName, CurSockAddrIPv4.sin_port);\r
2489 \r
2490                                 Socks5Reply.Result = -1;\r
2491                                 // 同時接続対応\r
2492 //                              if((SocksSendCmd(listen_skt, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2493 //                                 (Socks5GetCmdReply(listen_skt, &Socks5Reply) != FFFTP_SUCCESS) || \r
2494 //                                 (Socks5Reply.Result != SOCKS5_RES_OK))\r
2495                                 if((SocksSendCmd(listen_skt, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2496                                    (Socks5GetCmdReply(listen_skt, &Socks5Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
2497                                    (Socks5Reply.Result != SOCKS5_RES_OK))\r
2498                                 {\r
2499                                         SetTaskMsg(MSGJPN029, Socks5Reply.Result);\r
2500                                         DoClose(listen_skt);\r
2501                                         listen_skt = INVALID_SOCKET;\r
2502                                 }\r
2503 \r
2504                                 // IPv6対応\r
2505 //                              if(Socks5Reply.AdrsInt == 0)\r
2506 //                                      Socks5Reply.AdrsInt = SocksSockAddr.sin_addr.s_addr;\r
2507 \r
2508                                 // IPv6対応\r
2509 //                              a = (char *)&Socks5Reply.AdrsInt;\r
2510 //                              p = (char *)&Socks5Reply.Port;\r
2511                                 a = (char *)&Socks5Reply._dummy[0];\r
2512                                 p = (char *)&Socks5Reply._dummy[4];\r
2513                         }\r
2514                 }\r
2515                 else\r
2516                 {\r
2517                         /*===== SOCKSを使わない =====*/\r
2518                         DoPrintf("Use normal BIND");\r
2519                         saCtrlAddr.sin_port = htons(0);\r
2520                         saCtrlAddr.sin_family = AF_INET;\r
2521                         saCtrlAddr.sin_addr.s_addr = 0;\r
2522 \r
2523                         if(bind(listen_skt, (struct sockaddr *)&saCtrlAddr, sizeof(struct sockaddr)) != SOCKET_ERROR)\r
2524                         {\r
2525                                 iLength = sizeof(saCtrlAddr);\r
2526                                 if(getsockname(listen_skt, (struct sockaddr *)&saCtrlAddr, &iLength) != SOCKET_ERROR)\r
2527                                 {\r
2528                                         if(do_listen(listen_skt, 1) == 0)\r
2529                                         {\r
2530                                                 iLength = sizeof(saTmpAddr);\r
2531                                                 if(getsockname(ctrl_skt, (struct sockaddr *)&saTmpAddr, &iLength) == SOCKET_ERROR)\r
2532                                                         ReportWSError("getsockname", WSAGetLastError());\r
2533 \r
2534                                                 a = (char *)&saTmpAddr.sin_addr;\r
2535                                                 p = (char *)&saCtrlAddr.sin_port;\r
2536                                         }\r
2537                                         else\r
2538                                         {\r
2539                                                 ReportWSError("listen", WSAGetLastError());\r
2540                                                 do_closesocket(listen_skt);\r
2541                                                 listen_skt = INVALID_SOCKET;\r
2542                                         }\r
2543                                 }\r
2544                                 else\r
2545                                 {\r
2546                                         ReportWSError("getsockname", WSAGetLastError());\r
2547                                         do_closesocket(listen_skt);\r
2548                                         listen_skt = INVALID_SOCKET;\r
2549                                 }\r
2550                         }\r
2551                         else\r
2552                         {\r
2553                                 ReportWSError("bind", WSAGetLastError());\r
2554                                 do_closesocket(listen_skt);\r
2555                                 listen_skt = INVALID_SOCKET;\r
2556                         }\r
2557 \r
2558                         if(listen_skt == INVALID_SOCKET)\r
2559                                 SetTaskMsg(MSGJPN030);\r
2560                 }\r
2561         }\r
2562         else\r
2563                 ReportWSError("socket create", WSAGetLastError());\r
2564 \r
2565         if(listen_skt != INVALID_SOCKET)\r
2566         {\r
2567 #define  UC(b)  (((int)b)&0xff)\r
2568                 // 同時接続対応\r
2569 //              if((command(ctrl_skt,NULL, &CancelFlg, "PORT %d,%d,%d,%d,%d,%d",\r
2570 //                              UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]),\r
2571 //                              UC(p[0]), UC(p[1])) / 100) != FTP_COMPLETE)\r
2572                 if((command(ctrl_skt,NULL, CancelCheckWork, "PORT %d,%d,%d,%d,%d,%d",\r
2573                                 UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]),\r
2574                                 UC(p[0]), UC(p[1])) / 100) != FTP_COMPLETE)\r
2575                 {\r
2576                         SetTaskMsg(MSGJPN031);\r
2577                         do_closesocket(listen_skt);\r
2578                         listen_skt = INVALID_SOCKET;\r
2579                 }\r
2580 //              else\r
2581 //                      DoPrintf("Skt=%u : listener %s port %u",listen_skt,inet_ntoa(saCtrlAddr.sin_addr),ntohs(saCtrlAddr.sin_port));\r
2582         }\r
2583 \r
2584         return(listen_skt);\r
2585 }\r
2586 \r
2587 \r
2588 SOCKET GetFTPListenSocketIPv6(SOCKET ctrl_skt, int *CancelCheckWork)\r
2589 {\r
2590     SOCKET listen_skt;\r
2591     int iLength;\r
2592     char *a,*p;\r
2593         struct sockaddr_in6 saCtrlAddr;\r
2594         struct sockaddr_in6 saTmpAddr;\r
2595         SOCKS5REQUEST Socks5Cmd;\r
2596         SOCKS5REPLY Socks5Reply;\r
2597 \r
2598         int Len;\r
2599         int Fwall;\r
2600 \r
2601         char Adrs[40];\r
2602 \r
2603         Fwall = FWALL_NONE;\r
2604         if(AskHostFireWall() == YES)\r
2605                 Fwall = FwallType;\r
2606 \r
2607         if((listen_skt = do_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP)) != INVALID_SOCKET)\r
2608         {\r
2609                 if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2610                 {\r
2611                         /*===== SOCKS5を使う =====*/\r
2612                         DoPrintf("Use SOCKS5 BIND");\r
2613                         if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddrIPv6, sizeof(SocksSockAddrIPv6), CancelCheckWork) != SOCKET_ERROR)\r
2614                         {\r
2615                                 if(Socks5SelMethod(listen_skt, CancelCheckWork) == FFFTP_FAIL)\r
2616                                 {\r
2617                                         DoClose(listen_skt);\r
2618                                         listen_skt = INVALID_SOCKET;\r
2619                                         return(listen_skt);\r
2620                                 }\r
2621 \r
2622                                 Len = Socks5MakeCmdPacketIPv6(&Socks5Cmd, SOCKS5_CMD_BIND, UseIPadrs, (char*)&CurSockAddrIPv6.sin6_addr, DomainName, CurSockAddrIPv6.sin6_port);\r
2623 \r
2624                                 Socks5Reply.Result = -1;\r
2625                                 // 同時接続対応\r
2626 //                              if((SocksSendCmd(listen_skt, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2627 //                                 (Socks5GetCmdReply(listen_skt, &Socks5Reply) != FFFTP_SUCCESS) || \r
2628 //                                 (Socks5Reply.Result != SOCKS5_RES_OK))\r
2629                                 if((SocksSendCmd(listen_skt, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2630                                    (Socks5GetCmdReply(listen_skt, &Socks5Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
2631                                    (Socks5Reply.Result != SOCKS5_RES_OK))\r
2632                                 {\r
2633                                         SetTaskMsg(MSGJPN029, Socks5Reply.Result);\r
2634                                         DoClose(listen_skt);\r
2635                                         listen_skt = INVALID_SOCKET;\r
2636                                 }\r
2637 \r
2638                                 // IPv6対応\r
2639 //                              if(Socks5Reply.AdrsInt == 0)\r
2640 //                                      Socks5Reply.AdrsInt = SocksSockAddr.sin_addr.s_addr;\r
2641 \r
2642                                 // IPv6対応\r
2643 //                              a = (char *)&Socks5Reply.AdrsInt;\r
2644 //                              p = (char *)&Socks5Reply.Port;\r
2645                                 a = (char *)&Socks5Reply._dummy[0];\r
2646                                 p = (char *)&Socks5Reply._dummy[16];\r
2647                         }\r
2648                 }\r
2649                 else\r
2650                 {\r
2651                         /*===== SOCKSを使わない =====*/\r
2652                         DoPrintf("Use normal BIND");\r
2653                         saCtrlAddr.sin6_port = htons(0);\r
2654                         saCtrlAddr.sin6_family = AF_INET6;\r
2655                         memset(&saCtrlAddr.sin6_addr, 0, 16);\r
2656 \r
2657                         if(bind(listen_skt, (struct sockaddr *)&saCtrlAddr, sizeof(struct sockaddr_in6)) != SOCKET_ERROR)\r
2658                         {\r
2659                                 iLength = sizeof(saCtrlAddr);\r
2660                                 if(getsockname(listen_skt, (struct sockaddr *)&saCtrlAddr, &iLength) != SOCKET_ERROR)\r
2661                                 {\r
2662                                         if(do_listen(listen_skt, 1) == 0)\r
2663                                         {\r
2664                                                 iLength = sizeof(saTmpAddr);\r
2665                                                 if(getsockname(ctrl_skt, (struct sockaddr *)&saTmpAddr, &iLength) == SOCKET_ERROR)\r
2666                                                         ReportWSError("getsockname", WSAGetLastError());\r
2667 \r
2668                                                 a = (char *)&saTmpAddr.sin6_addr;\r
2669                                                 p = (char *)&saCtrlAddr.sin6_port;\r
2670                                         }\r
2671                                         else\r
2672                                         {\r
2673                                                 ReportWSError("listen", WSAGetLastError());\r
2674                                                 do_closesocket(listen_skt);\r
2675                                                 listen_skt = INVALID_SOCKET;\r
2676                                         }\r
2677                                 }\r
2678                                 else\r
2679                                 {\r
2680                                         ReportWSError("getsockname", WSAGetLastError());\r
2681                                         do_closesocket(listen_skt);\r
2682                                         listen_skt = INVALID_SOCKET;\r
2683                                 }\r
2684                         }\r
2685                         else\r
2686                         {\r
2687                                 ReportWSError("bind", WSAGetLastError());\r
2688                                 do_closesocket(listen_skt);\r
2689                                 listen_skt = INVALID_SOCKET;\r
2690                         }\r
2691 \r
2692                         if(listen_skt == INVALID_SOCKET)\r
2693                                 SetTaskMsg(MSGJPN030);\r
2694                 }\r
2695         }\r
2696         else\r
2697                 ReportWSError("socket create", WSAGetLastError());\r
2698 \r
2699         if(listen_skt != INVALID_SOCKET)\r
2700         {\r
2701 #define  UC(b)  (((int)b)&0xff)\r
2702                 // 同時接続対応\r
2703 //              if((command(ctrl_skt,NULL, &CancelFlg, "PORT %d,%d,%d,%d,%d,%d",\r
2704 //                              UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]),\r
2705 //                              UC(p[0]), UC(p[1])) / 100) != FTP_COMPLETE)\r
2706                 if((command(ctrl_skt,NULL, CancelCheckWork, "EPRT |2|%s|%d|",\r
2707                                 AddressToStringIPv6(Adrs, a),\r
2708                                 (UC(p[0]) << 8) | UC(p[1])) / 100) != FTP_COMPLETE)\r
2709                 {\r
2710                         SetTaskMsg(MSGJPN031);\r
2711                         do_closesocket(listen_skt);\r
2712                         listen_skt = INVALID_SOCKET;\r
2713                 }\r
2714 //              else\r
2715 //                      DoPrintf("Skt=%u : listener %s port %u",listen_skt,inet_ntoa(saCtrlAddr.sin_addr),ntohs(saCtrlAddr.sin_port));\r
2716         }\r
2717 \r
2718         return(listen_skt);\r
2719 }\r
2720 \r
2721 \r
2722 /*----- ホストへ接続処理中かどうかを返す---------------------------------------\r
2723 *\r
2724 *       Parameter\r
2725 *               なし\r
2726 *\r
2727 *       Return Value\r
2728 *               int ステータス\r
2729 *                       YES/NO\r
2730 *----------------------------------------------------------------------------*/\r
2731 \r
2732 int AskTryingConnect(void)\r
2733 {\r
2734         return(TryConnect);\r
2735 }\r
2736 \r
2737 \r
2738 #if 0\r
2739 ///*----- ブロッキングコールのフックコールバック --------------------------------\r
2740 //*\r
2741 //*     Parameter\r
2742 //*             なし\r
2743 //*\r
2744 //*     Return Value\r
2745 //*             BOOL FALSE\r
2746 //*----------------------------------------------------------------------------*/\r
2747 //\r
2748 //static BOOL CALLBACK BlkHookFnc(void)\r
2749 //{\r
2750 //      BackgrndMessageProc();\r
2751 //\r
2752 //      if(CancelFlg == YES)\r
2753 //      {\r
2754 //              SetTaskMsg(MSGJPN032);\r
2755 //              WSACancelBlockingCall();\r
2756 //              CancelFlg = NO;\r
2757 //      }\r
2758 //      return(FALSE);\r
2759 //}\r
2760 #endif\r
2761 \r
2762 \r
2763 \r
2764 /*----- SOCKS5のコマンドパケットを作成する ------------------------------------\r
2765 *\r
2766 *       Parameter\r
2767 *               SOCKS5REQUEST *Packet : パケットを作成するワーク\r
2768 *               char Cmd : コマンド\r
2769 *               int ValidIP : IPアドレスを使うかどうか(YES/NO)\r
2770 *               ulong IP : IPアドレス\r
2771 *               char *Host : ホスト名\r
2772 *               ushort Port : ポート\r
2773 *\r
2774 *       Return Value\r
2775 *               int コマンドパケットの長さ\r
2776 *----------------------------------------------------------------------------*/\r
2777 \r
2778 static int Socks5MakeCmdPacket(SOCKS5REQUEST *Packet, char Cmd, int ValidIP, ulong IP, char *Host, ushort Port)\r
2779 {\r
2780         uchar *Pos;\r
2781         int Len;\r
2782         int TotalLen;\r
2783 \r
2784         Pos = (uchar *)Packet;\r
2785         Pos += SOCKS5REQUEST_SIZE;\r
2786         TotalLen = SOCKS5REQUEST_SIZE + 2;      /* +2はポートの分 */\r
2787 \r
2788         Packet->Ver = SOCKS5_VER;\r
2789         Packet->Cmd = Cmd;\r
2790         Packet->Rsv = 0;\r
2791         if(ValidIP == YES)\r
2792         {\r
2793                 /* IPアドレスを指定 */\r
2794                 Packet->Type = SOCKS5_ADRS_IPV4;\r
2795                 *((ulong *)Pos) = IP;\r
2796                 Pos += 4;\r
2797                 TotalLen += 4;\r
2798         }\r
2799         else\r
2800         {\r
2801                 /* ホスト名を指定 */\r
2802                 Packet->Type = SOCKS5_ADRS_NAME;\r
2803                 Len = strlen(Host);\r
2804                 *Pos++ = Len;\r
2805                 strcpy(Pos, Host);\r
2806                 Pos += Len;\r
2807                 TotalLen += Len + 1;\r
2808      &nbs