OSDN Git Service

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