OSDN Git Service

Fix bugs of deadlock around simultaneous connection.
[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 #include <winsock.h>\r
39 #include <windowsx.h>\r
40 #include <commctrl.h>\r
41 \r
42 #include "common.h"\r
43 #include "resource.h"\r
44 \r
45 #include <htmlhelp.h>\r
46 #include "helpid.h"\r
47 \r
48 // UTF-8対応\r
49 #undef __MBSWRAPPER_H__\r
50 #include "mbswrapper.h"\r
51 \r
52 \r
53 /*===== プロトタイプ =====*/\r
54 \r
55 static BOOL CALLBACK QuickConDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
56 static int SendInitCommand(char *Cmd);\r
57 static void AskUseFireWall(char *Host, int *Fire, int *Pasv, int *List);\r
58 static void SaveCurrentSetToHistory(void);\r
59 static int ReConnectSkt(SOCKET *Skt);\r
60 static SOCKET DoConnect(char *Host, char *User, char *Pass, char *Acct, int Port, int Fwall, int SavePass, int Security);\r
61 static int CheckOneTimePassword(char *Pass, char *Reply, int Type);\r
62 static BOOL CALLBACK BlkHookFnc(void);\r
63 static int Socks5MakeCmdPacket(SOCKS5REQUEST *Packet, char Cmd, int ValidIP, ulong IP, char *Host, ushort Port);\r
64 static int SocksSendCmd(SOCKET Socket, void *Data, int Size, int *CancelCheckWork);\r
65 static int Socks5GetCmdReply(SOCKET Socket, SOCKS5REPLY *Packet);\r
66 static int Socks4GetCmdReply(SOCKET Socket, SOCKS4REPLY *Packet);\r
67 static int Socks5SelMethod(SOCKET Socket, int *CancelCheckWork);\r
68 \r
69 /*===== 外部参照 =====*/\r
70 \r
71 extern char FilterStr[FILTER_EXT_LEN+1];\r
72 extern char TitleHostName[HOST_ADRS_LEN+1];\r
73 extern int CancelFlg;\r
74 \r
75 /* 設定値 */\r
76 extern char UserMailAdrs[USER_MAIL_LEN+1];\r
77 extern char FwallHost[HOST_ADRS_LEN+1];\r
78 extern char FwallUser[USER_NAME_LEN+1];\r
79 extern char FwallPass[PASSWORD_LEN+1];\r
80 extern int FwallPort;\r
81 extern int FwallType;\r
82 extern int FwallDefault;\r
83 extern int FwallSecurity;\r
84 extern int FwallResolv;\r
85 extern int FwallLower;\r
86 extern int FwallDelimiter;\r
87 extern int PasvDefault;\r
88 extern int QuickAnonymous;\r
89 \r
90 /*===== ローカルなワーク =====*/\r
91 \r
92 static int Anonymous;\r
93 static int TryConnect = NO;\r
94 static SOCKET CmdCtrlSocket = INVALID_SOCKET;\r
95 static SOCKET TrnCtrlSocket = INVALID_SOCKET;\r
96 static HOSTDATA CurHost;\r
97 \r
98 /* 接続中の接続先、SOCKSサーバのアドレス情報を保存しておく */\r
99 /* この情報はlistenソケットを取得する際に用いる */\r
100 static struct sockaddr_in SocksSockAddr;        /* SOCKSサーバのアドレス情報 */\r
101 static struct sockaddr_in CurSockAddr;          /* 接続先ホストのアドレス情報 */\r
102 \r
103 static int UseIPadrs;\r
104 static char DomainName[HOST_ADRS_LEN+1];\r
105 \r
106 \r
107 \r
108 \r
109 /*----- ホスト一覧を使ってホストへ接続 ----------------------------------------\r
110 *\r
111 *       Parameter\r
112 *               int Type : ダイアログのタイプ (DLG_TYPE_xxx)\r
113 *               int Num : 接続するホスト番号(0~, -1=ダイアログを出す)\r
114 \r
115 *       Return Value\r
116 *               なし\r
117 *----------------------------------------------------------------------------*/\r
118 \r
119 void ConnectProc(int Type, int Num)\r
120 {\r
121         int Save;\r
122         int LFSort;\r
123         int LDSort;\r
124         int RFSort;\r
125         int RDSort;\r
126 \r
127         SaveBookMark();\r
128         SaveCurrentSetToHost();\r
129 \r
130         if((Num >= 0) || (SelectHost(Type) == YES))\r
131         {\r
132                 if(Num >= 0)\r
133                         SetCurrentHost(Num);\r
134 \r
135                 /* 接続中なら切断する */\r
136                 if(CmdCtrlSocket != INVALID_SOCKET)\r
137                         DisconnectProc();\r
138 \r
139                 SetTaskMsg("----------------------------");\r
140 \r
141                 InitPWDcommand();\r
142                 CopyHostFromList(AskCurrentHost(), &CurHost);\r
143 \r
144                 if(ConnectRas(CurHost.Dialup, CurHost.DialupAlways, CurHost.DialupNotify, CurHost.DialEntry) == FFFTP_SUCCESS)\r
145                 {\r
146                         SetHostKanaCnvImm(CurHost.KanaCnv);\r
147                         SetHostKanjiCodeImm(CurHost.KanjiCode);\r
148                         SetSyncMoveMode(CurHost.SyncMove);\r
149 \r
150                         if((AskSaveSortToHost() == YES) && (CurHost.Sort != SORT_NOTSAVED))\r
151                         {\r
152                                 DecomposeSortType(CurHost.Sort, &LFSort, &LDSort, &RFSort, &RDSort);\r
153                                 SetSortTypeImm(LFSort, LDSort, RFSort, RDSort);\r
154                                 ReSortDispList(WIN_LOCAL, &CancelFlg);\r
155                         }\r
156 \r
157                         Save = NO;\r
158                         if(strlen(CurHost.PassWord) > 0)\r
159                                 Save = YES;\r
160 \r
161                         DisableUserOpe();\r
162                         CmdCtrlSocket = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, Save, CurHost.Security);\r
163                         TrnCtrlSocket = CmdCtrlSocket;\r
164 \r
165                         if(CmdCtrlSocket != INVALID_SOCKET)\r
166                         {\r
167                                 strcpy(TitleHostName, CurHost.HostName);\r
168                                 DispWindowTitle();\r
169                                 SoundPlay(SND_CONNECT);\r
170 \r
171                                 SendInitCommand(CurHost.InitCmd);\r
172 \r
173                                 if(strlen(CurHost.LocalInitDir) > 0)\r
174                                 {\r
175                                         DoLocalCWD(CurHost.LocalInitDir);\r
176                                         GetLocalDirForWnd();\r
177                                 }\r
178                                 InitTransCurDir();\r
179                                 DoCWD(CurHost.RemoteInitDir, YES, YES, YES);\r
180 \r
181                                 LoadBookMark();\r
182                                 GetRemoteDirForWnd(CACHE_NORMAL, &CancelFlg);\r
183                         }\r
184                         else\r
185                                 SoundPlay(SND_ERROR);\r
186 \r
187                         EnableUserOpe();\r
188                 }\r
189                 else\r
190                         SetTaskMsg(MSGJPN001);\r
191         }\r
192         return;\r
193 }\r
194 \r
195 \r
196 /*----- ホスト名を入力してホストへ接続 ----------------------------------------\r
197 *\r
198 *       Parameter\r
199 *               なし\r
200 *\r
201 *       Return Value\r
202 *               なし\r
203 *----------------------------------------------------------------------------*/\r
204 \r
205 void QuickConnectProc(void)\r
206 {\r
207         char Tmp[FMAX_PATH+1 + USER_NAME_LEN+1 + PASSWORD_LEN+1 + 2];\r
208         char File[FMAX_PATH+1];\r
209 \r
210         SaveBookMark();\r
211         SaveCurrentSetToHost();\r
212 \r
213         if(DialogBoxParam(GetFtpInst(), MAKEINTRESOURCE(hostname_dlg), GetMainHwnd(), QuickConDialogCallBack, (LPARAM)Tmp) == YES)\r
214         {\r
215                 /* 接続中なら切断する */\r
216                 if(CmdCtrlSocket != INVALID_SOCKET)\r
217                         DisconnectProc();\r
218 \r
219                 SetTaskMsg("----------------------------");\r
220 \r
221                 InitPWDcommand();\r
222                 CopyDefaultHost(&CurHost);\r
223                 if(SplitUNCpath(Tmp, CurHost.HostAdrs, CurHost.RemoteInitDir, File, CurHost.UserName, CurHost.PassWord, &CurHost.Port) == FFFTP_SUCCESS)\r
224                 {\r
225                         if(strlen(CurHost.UserName) == 0)\r
226                         {\r
227                                 strcpy(CurHost.UserName, Tmp + FMAX_PATH+1);\r
228                                 strcpy(CurHost.PassWord, Tmp + FMAX_PATH+1 + USER_NAME_LEN+1);\r
229                         }\r
230 \r
231                         SetCurrentHost(HOSTNUM_NOENTRY);\r
232                         AskUseFireWall(CurHost.HostAdrs, &CurHost.FireWall, &CurHost.Pasv, &CurHost.ListCmdOnly);\r
233                         CurHost.FireWall = (int)Tmp[FMAX_PATH+1 + USER_NAME_LEN+1 + PASSWORD_LEN+1];\r
234                         CurHost.Pasv = (int)Tmp[FMAX_PATH+1 + USER_NAME_LEN+1 + PASSWORD_LEN+1 + 1];\r
235 \r
236                         SetHostKanaCnvImm(CurHost.KanaCnv);\r
237                         SetHostKanjiCodeImm(CurHost.KanjiCode);\r
238                         SetSyncMoveMode(CurHost.SyncMove);\r
239 \r
240                         DisableUserOpe();\r
241                         CmdCtrlSocket = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security);\r
242                         TrnCtrlSocket = CmdCtrlSocket;\r
243 \r
244                         if(CmdCtrlSocket != INVALID_SOCKET)\r
245                         {\r
246                                 strcpy(TitleHostName, CurHost.HostAdrs);\r
247                                 DispWindowTitle();\r
248                                 SoundPlay(SND_CONNECT);\r
249 \r
250                                 InitTransCurDir();\r
251                                 DoCWD(CurHost.RemoteInitDir, YES, YES, YES);\r
252 \r
253                                 GetRemoteDirForWnd(CACHE_NORMAL, &CancelFlg);\r
254                                 EnableUserOpe();\r
255 \r
256                                 if(strlen(File) > 0)\r
257                                         DirectDownLoadProc(File);\r
258                         }\r
259                         else\r
260                         {\r
261                                 SoundPlay(SND_ERROR);\r
262                                 EnableUserOpe();\r
263                         }\r
264                 }\r
265         }\r
266         return;\r
267 }\r
268 \r
269 \r
270 /*----- クイック接続ダイアログのコールバック ----------------------------------\r
271 *\r
272 *       Parameter\r
273 *               HWND hDlg : ウインドウハンドル\r
274 *               UINT message : メッセージ番号\r
275 *               WPARAM wParam : メッセージの WPARAM 引数\r
276 *               LPARAM lParam : メッセージの LPARAM 引数\r
277 *\r
278 *       Return Value\r
279 *               BOOL TRUE/FALSE\r
280 *----------------------------------------------------------------------------*/\r
281 \r
282 static BOOL CALLBACK QuickConDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
283 {\r
284         static char *Buf;\r
285         int i;\r
286         HISTORYDATA Tmp;\r
287 \r
288 //char Str[HOST_ADRS_LEN+USER_NAME_LEN+INIT_DIR_LEN+5+1];\r
289 \r
290         switch (iMessage)\r
291         {\r
292                 case WM_INITDIALOG :\r
293                         SendDlgItemMessage(hDlg, QHOST_HOST, CB_LIMITTEXT, FMAX_PATH, 0);\r
294                         SendDlgItemMessage(hDlg, QHOST_HOST, WM_SETTEXT, 0, (LPARAM)"");\r
295                         SendDlgItemMessage(hDlg, QHOST_USER, EM_LIMITTEXT, USER_NAME_LEN, 0);\r
296                         if(QuickAnonymous == YES)\r
297                         {\r
298                                 SendDlgItemMessage(hDlg, QHOST_USER, WM_SETTEXT, 0, (LPARAM)"anonymous");\r
299                                 SendDlgItemMessage(hDlg, QHOST_PASS, WM_SETTEXT, 0, (LPARAM)UserMailAdrs);\r
300                         }\r
301                         else\r
302                         {\r
303                                 SendDlgItemMessage(hDlg, QHOST_USER, WM_SETTEXT, 0, (LPARAM)"");\r
304                                 SendDlgItemMessage(hDlg, QHOST_PASS, WM_SETTEXT, 0, (LPARAM)"");\r
305                         }\r
306                         SendDlgItemMessage(hDlg, QHOST_PASS, EM_LIMITTEXT, PASSWORD_LEN, 0);\r
307                         SendDlgItemMessage(hDlg, QHOST_FWALL, BM_SETCHECK, FwallDefault, 0);\r
308                         SendDlgItemMessage(hDlg, QHOST_PASV, BM_SETCHECK, PasvDefault, 0);\r
309                         for(i = 0; i < HISTORY_MAX; i++)\r
310                         {\r
311                                 if(GetHistoryByNum(i, &Tmp) == FFFTP_SUCCESS)\r
312                                 {\r
313 //sprintf(Str, "%s (%s) %s", Tmp.HostAdrs, Tmp.UserName, Tmp.RemoteInitDir);\r
314 //SendDlgItemMessage(hDlg, QHOST_HOST, CB_ADDSTRING, 0, (LPARAM)Str);\r
315                                         SendDlgItemMessage(hDlg, QHOST_HOST, CB_ADDSTRING, 0, (LPARAM)Tmp.HostAdrs);\r
316                                 }\r
317                         }\r
318                         Buf = (char *)lParam;\r
319                         return(TRUE);\r
320 \r
321                 case WM_COMMAND :\r
322                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
323                         {\r
324                                 case IDOK :\r
325                                         SendDlgItemMessage(hDlg, QHOST_HOST, WM_GETTEXT, FMAX_PATH+1, (LPARAM)Buf);\r
326                                         SendDlgItemMessage(hDlg, QHOST_USER, WM_GETTEXT, USER_NAME_LEN+1, (LPARAM)Buf + FMAX_PATH+1);\r
327                                         SendDlgItemMessage(hDlg, QHOST_PASS, WM_GETTEXT, PASSWORD_LEN+1, (LPARAM)Buf + FMAX_PATH+1 + USER_NAME_LEN+1);\r
328                                         *(Buf + FMAX_PATH+1 + USER_NAME_LEN+1 + PASSWORD_LEN+1) = (char)SendDlgItemMessage(hDlg, QHOST_FWALL, BM_GETCHECK, 0, 0);\r
329                                         *(Buf + FMAX_PATH+1 + USER_NAME_LEN+1 + PASSWORD_LEN+1+1) = (char)SendDlgItemMessage(hDlg, QHOST_PASV, BM_GETCHECK, 0, 0);\r
330                                         EndDialog(hDlg, YES);\r
331                                         break;\r
332 \r
333                                 case IDCANCEL :\r
334                                         EndDialog(hDlg, NO);\r
335                                         break;\r
336 \r
337 //                              case QHOST_HOST :\r
338 //                                      if(HIWORD(wParam) == CBN_EDITCHANGE)\r
339 //                                              DoPrintf("EDIT");\r
340 //                                      break;\r
341                         }\r
342             return(TRUE);\r
343         }\r
344         return(FALSE);\r
345 }\r
346 \r
347 \r
348 /*----- 指定したホスト名でホストへ接続 ----------------------------------------\r
349 *\r
350 *       Parameter\r
351 *               char *unc : UNC文字列\r
352 *               int Kanji : ホストの漢字コード (KANJI_xxx)\r
353 *               int Kana : 半角かな→全角変換モード (YES/NO)\r
354 *               int Fkanji : ファイル名の漢字コード (KANJI_xxx)\r
355 *               int TrMode : 転送モード (TYPE_xx)\r
356 *\r
357 *       Return Value\r
358 *               なし\r
359 *----------------------------------------------------------------------------*/\r
360 \r
361 void DirectConnectProc(char *unc, int Kanji, int Kana, int Fkanji, int TrMode)\r
362 {\r
363         char Host[HOST_ADRS_LEN+1];\r
364         char Path[FMAX_PATH+1];\r
365         char File[FMAX_PATH+1];\r
366         char User[USER_NAME_LEN+1];\r
367         char Pass[PASSWORD_LEN+1];\r
368         int Port;\r
369 \r
370         SaveBookMark();\r
371         SaveCurrentSetToHost();\r
372 \r
373         /* 接続中なら切断する */\r
374         if(CmdCtrlSocket != INVALID_SOCKET)\r
375                 DisconnectProc();\r
376 \r
377         SetTaskMsg("----------------------------");\r
378 \r
379         InitPWDcommand();\r
380         if(SplitUNCpath(unc, Host, Path, File, User, Pass, &Port) == FFFTP_SUCCESS)\r
381         {\r
382                 if(strlen(User) == 0)\r
383                 {\r
384                         strcpy(User, "anonymous");\r
385                         strcpy(Pass, UserMailAdrs);\r
386                 }\r
387 \r
388                 CopyDefaultHost(&CurHost);\r
389 \r
390                 SetCurrentHost(HOSTNUM_NOENTRY);\r
391                 strcpy(CurHost.HostAdrs, Host);\r
392                 strcpy(CurHost.UserName, User);\r
393                 strcpy(CurHost.PassWord, Pass);\r
394                 strcpy(CurHost.RemoteInitDir, Path);\r
395                 AskUseFireWall(CurHost.HostAdrs, &CurHost.FireWall, &CurHost.Pasv, &CurHost.ListCmdOnly);\r
396                 CurHost.Port = Port;\r
397                 CurHost.KanjiCode = Kanji;\r
398                 CurHost.KanaCnv = Kana;\r
399                 CurHost.NameKanjiCode = Fkanji;\r
400                 CurHost.KanaCnv = YES;                  /* とりあえず */\r
401 \r
402                 SetHostKanaCnvImm(CurHost.KanaCnv);\r
403                 SetHostKanjiCodeImm(CurHost.KanjiCode);\r
404                 SetSyncMoveMode(CurHost.SyncMove);\r
405 \r
406                 if(TrMode != TYPE_DEFAULT)\r
407                 {\r
408                         SetTransferTypeImm(TrMode);\r
409                         DispTransferType();\r
410                 }\r
411 \r
412                 DisableUserOpe();\r
413                 CmdCtrlSocket = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security);\r
414                 TrnCtrlSocket = CmdCtrlSocket;\r
415 \r
416                 if(CmdCtrlSocket != INVALID_SOCKET)\r
417                 {\r
418                         strcpy(TitleHostName, CurHost.HostAdrs);\r
419                         DispWindowTitle();\r
420                         SoundPlay(SND_CONNECT);\r
421 \r
422                         InitTransCurDir();\r
423                         DoCWD(CurHost.RemoteInitDir, YES, YES, YES);\r
424 \r
425                         GetRemoteDirForWnd(CACHE_NORMAL, &CancelFlg);\r
426                         EnableUserOpe();\r
427 \r
428                         if(strlen(File) > 0)\r
429                                 DirectDownLoadProc(File);\r
430                         else\r
431                                 ResetAutoExitFlg();\r
432                 }\r
433                 else\r
434                 {\r
435                         SoundPlay(SND_ERROR);\r
436                         EnableUserOpe();\r
437                 }\r
438         }\r
439         return;\r
440 }\r
441 \r
442 \r
443 /*----- ホストのヒストリで指定されたホストへ接続 ------------------------------\r
444 *\r
445 *       Parameter\r
446 *               int MenuCmd : 取り出すヒストリに割り当てられたメニューコマンド\r
447 *\r
448 *       Return Value\r
449 *               なし\r
450 *----------------------------------------------------------------------------*/\r
451 \r
452 void HistoryConnectProc(int MenuCmd)\r
453 {\r
454         HISTORYDATA Hist;\r
455         int LFSort;\r
456         int LDSort;\r
457         int RFSort;\r
458         int RDSort;\r
459 \r
460         if(GetHistoryByCmd(MenuCmd, &Hist) == FFFTP_SUCCESS)\r
461         {\r
462                 SaveBookMark();\r
463                 SaveCurrentSetToHost();\r
464 \r
465                 /* 接続中なら切断する */\r
466                 if(CmdCtrlSocket != INVALID_SOCKET)\r
467                         DisconnectProc();\r
468 \r
469                 SetTaskMsg("----------------------------");\r
470 \r
471                 InitPWDcommand();\r
472                 CopyHistoryToHost(&Hist, &CurHost);\r
473 \r
474                 if(ConnectRas(CurHost.Dialup, CurHost.DialupAlways, CurHost.DialupNotify, CurHost.DialEntry) == FFFTP_SUCCESS)\r
475                 {\r
476                         SetCurrentHost(HOSTNUM_NOENTRY);\r
477                         SetHostKanaCnvImm(CurHost.KanaCnv);\r
478                         SetHostKanjiCodeImm(CurHost.KanjiCode);\r
479                         SetSyncMoveMode(CurHost.SyncMove);\r
480 \r
481                         DecomposeSortType(CurHost.Sort, &LFSort, &LDSort, &RFSort, &RDSort);\r
482                         SetSortTypeImm(LFSort, LDSort, RFSort, RDSort);\r
483                         ReSortDispList(WIN_LOCAL, &CancelFlg);\r
484 \r
485                         SetTransferTypeImm(Hist.Type);\r
486                         DispTransferType();\r
487 \r
488                         DisableUserOpe();\r
489                         CmdCtrlSocket = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security);\r
490                         TrnCtrlSocket = CmdCtrlSocket;\r
491 \r
492                         if(CmdCtrlSocket != INVALID_SOCKET)\r
493                         {\r
494                                 strcpy(TitleHostName, CurHost.HostAdrs);\r
495                                 DispWindowTitle();\r
496                                 SoundPlay(SND_CONNECT);\r
497 \r
498                                 SendInitCommand(CurHost.InitCmd);\r
499 \r
500                                 DoLocalCWD(CurHost.LocalInitDir);\r
501                                 GetLocalDirForWnd();\r
502 \r
503                                 InitTransCurDir();\r
504                                 DoCWD(CurHost.RemoteInitDir, YES, YES, YES);\r
505 \r
506                                 GetRemoteDirForWnd(CACHE_NORMAL, &CancelFlg);\r
507                         }\r
508                         else\r
509                                 SoundPlay(SND_ERROR);\r
510 \r
511                         EnableUserOpe();\r
512                 }\r
513                 else\r
514                         SetTaskMsg(MSGJPN002);\r
515         }\r
516         else\r
517                 SoundPlay(SND_ERROR);\r
518 \r
519         return;\r
520 }\r
521 \r
522 \r
523 /*----- ホストの初期化コマンドを送る ------------------------------------------\r
524 *\r
525 *       Parameter\r
526 *               int Cmd : 初期化コマンドス\r
527 *\r
528 *       Return Value\r
529 *               なし\r
530 *\r
531 *       NOte\r
532 *               初期化コマンドは以下のようなフォーマットであること\r
533 *                       cmd1\0\r
534 *                       cmd1\r\ncmd2\r\n\0\r
535 *----------------------------------------------------------------------------*/\r
536 \r
537 static int SendInitCommand(char *Cmd)\r
538 {\r
539         char Tmp[INITCMD_LEN+1];\r
540         char *Pos;\r
541 \r
542         while(strlen(Cmd) > 0)\r
543         {\r
544                 strcpy(Tmp, Cmd);\r
545                 if((Pos = strchr(Tmp, '\r')) != NULL)\r
546                         *Pos = NUL;\r
547                 if(strlen(Tmp) > 0)\r
548                         DoQUOTE(Tmp);\r
549 \r
550                 if((Cmd = strchr(Cmd, '\n')) != NULL)\r
551                         Cmd++;\r
552                 else\r
553                         break;\r
554         }\r
555         return(0);\r
556 }\r
557 \r
558 \r
559 /*----- 指定のホストはFireWallを使う設定かどうかを返す ------------------------\r
560 *\r
561 *       Parameter\r
562 *               char *Hots : ホスト名\r
563 *               int *Fire : FireWallを使うかどうかを返すワーク\r
564 *               int *Pasv : PASVモードを返すワーク\r
565 *               int *List : LISTコマンドのみ使用フラグ\r
566 *\r
567 *       Return Value\r
568 *               なし\r
569 *----------------------------------------------------------------------------*/\r
570 \r
571 static void AskUseFireWall(char *Host, int *Fire, int *Pasv, int *List)\r
572 {\r
573         int i;\r
574         HOSTDATA Tmp;\r
575 \r
576         *Fire = FwallDefault;\r
577         *Pasv = PasvDefault;\r
578         *List = NO;\r
579 \r
580         i = 0;\r
581         while(CopyHostFromList(i, &Tmp) == FFFTP_SUCCESS)\r
582         {\r
583                 if(strcmp(Host, Tmp.HostAdrs) == 0)\r
584                 {\r
585                         *Fire = Tmp.FireWall;\r
586                         *Pasv = Tmp.Pasv;\r
587                         *List = Tmp.ListCmdOnly;\r
588                         break;\r
589                 }\r
590                 i++;\r
591         }\r
592         return;\r
593 }\r
594 \r
595 \r
596 /*----- 接続しているホストのアドレスを返す ------------------------------------\r
597 *\r
598 *       Parameter\r
599 *               なし\r
600 *\r
601 *       Return Value\r
602 *               char *ホストのアドレス\r
603 *----------------------------------------------------------------------------*/\r
604 \r
605 char *AskHostAdrs(void)\r
606 {\r
607         return(CurHost.HostAdrs);\r
608 }\r
609 \r
610 \r
611 /*----- 接続しているホストのポートを返す --------------------------------------\r
612 *\r
613 *       Parameter\r
614 *               なし\r
615 *\r
616 *       Return Value\r
617 *               int ホストのポート\r
618 *----------------------------------------------------------------------------*/\r
619 \r
620 int AskHostPort(void)\r
621 {\r
622         return(CurHost.Port);\r
623 }\r
624 \r
625 /*----- 接続しているホストのファイル名の漢字コードを返す ----------------------\r
626 *\r
627 *       Parameter\r
628 *               なし\r
629 *\r
630 *       Return Value\r
631 *               int 漢字コード (KANJI_xxx)\r
632 *----------------------------------------------------------------------------*/\r
633 \r
634 int AskHostNameKanji(void)\r
635 {\r
636         if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
637                 CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
638 \r
639         return(CurHost.NameKanjiCode);\r
640 }\r
641 \r
642 \r
643 /*----- 接続しているホストのファイル名の半角カナ変換フラグを返す --------------\r
644 *\r
645 *       Parameter\r
646 *               なし\r
647 *\r
648 *       Return Value\r
649 *               int 半角カナを全角に変換するかどうか (YES/NO)\r
650 *----------------------------------------------------------------------------*/\r
651 \r
652 int AskHostNameKana(void)\r
653 {\r
654         if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
655                 CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
656 \r
657         return(CurHost.NameKanaCnv);\r
658 }\r
659 \r
660 \r
661 /*----- 接続しているホストのLISTコマンドモードを返す --------------------------\r
662 *\r
663 *       Parameter\r
664 *               なし\r
665 *\r
666 *       Return Value\r
667 *               int LISTコマンドモード (YES/NO)\r
668 *----------------------------------------------------------------------------*/\r
669 \r
670 int AskListCmdMode(void)\r
671 {\r
672         if(CurHost.HostType == HTYPE_VMS)\r
673                 return(YES);\r
674         else\r
675         {\r
676                 if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
677                         CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
678                 return(CurHost.ListCmdOnly);\r
679         }\r
680 }\r
681 \r
682 \r
683 /*----- 接続しているホストでNLST -Rを使うかどうかを返す ------------------------\r
684 *\r
685 *       Parameter\r
686 *               なし\r
687 *\r
688 *       Return Value\r
689 *               int NLST -Rを使うかどうか (YES/NO)\r
690 *----------------------------------------------------------------------------*/\r
691 \r
692 int AskUseNLST_R(void)\r
693 {\r
694         if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
695                 CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
696 \r
697         return(CurHost.UseNLST_R);\r
698 }\r
699 \r
700 \r
701 /*----- 接続しているホストのChmodコマンドを返す -------------------------------\r
702 *\r
703 *       Parameter\r
704 *               なし\r
705 *\r
706 *       Return Value\r
707 *               char *Chmodコマンド\r
708 *----------------------------------------------------------------------------*/\r
709 \r
710 char *AskHostChmodCmd(void)\r
711 {\r
712         if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
713                 CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
714 \r
715         return(CurHost.ChmodCmd);\r
716 }\r
717 \r
718 \r
719 /*----- 接続しているホストのタイムゾーンを返す --------------------------------\r
720 *\r
721 *       Parameter\r
722 *               なし\r
723 *\r
724 *       Return Value\r
725 *               int タイムゾーン\r
726 *----------------------------------------------------------------------------*/\r
727 \r
728 int AskHostTimeZone(void)\r
729 {\r
730         if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
731                 CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
732 \r
733         return(CurHost.TimeZone);\r
734 }\r
735 \r
736 \r
737 /*----- 接続しているホストのPASVモードを返す ----------------------------------\r
738 *\r
739 *       Parameter\r
740 *               なし\r
741 *\r
742 *       Return Value\r
743 *               int PASVモードかどうか (YES/NO)\r
744 *----------------------------------------------------------------------------*/\r
745 \r
746 int AskPasvMode(void)\r
747 {\r
748         return(CurHost.Pasv);\r
749 }\r
750 \r
751 \r
752 /*----- 接続しているホストのLNSTファイル名を返す ------------------------------\r
753 *\r
754 *       Parameter\r
755 *               なし\r
756 *\r
757 *       Return Value\r
758 *               char *ファイル名/オプション\r
759 *----------------------------------------------------------------------------*/\r
760 \r
761 char *AskHostLsName(void)\r
762 {\r
763         if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
764                 CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
765 \r
766         return(CurHost.LsName);\r
767 }\r
768 \r
769 \r
770 /*----- 接続しているホストのホストタイプを返す --------------------------------\r
771 *\r
772 *       Parameter\r
773 *               なし\r
774 *\r
775 *       Return Value\r
776 *               char *ファイル名/オプション\r
777 *----------------------------------------------------------------------------*/\r
778 \r
779 int AskHostType(void)\r
780 {\r
781         if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
782                 CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
783 \r
784         return(CurHost.HostType);\r
785 }\r
786 \r
787 \r
788 /*----- 接続しているホストはFireWallを使うホストかどうかを返す ----------------\r
789 *\r
790 *       Parameter\r
791 *               なし\r
792 *\r
793 *       Return Value\r
794 *               int FireWallを使うかどうか (YES/NO)\r
795 *----------------------------------------------------------------------------*/\r
796 \r
797 int AskHostFireWall(void)\r
798 {\r
799         return(CurHost.FireWall);\r
800 }\r
801 \r
802 \r
803 /*----- 接続しているホストでフルパスでファイルアクセスしないかどうかを返す ----\r
804 *\r
805 *       Parameter\r
806 *               なし\r
807 *\r
808 *       Return Value\r
809 *               int フルパスでアクセスしない (YES=フルパス禁止/NO)\r
810 *----------------------------------------------------------------------------*/\r
811 \r
812 int AskNoFullPathMode(void)\r
813 {\r
814         if(CurHost.HostType == HTYPE_VMS)\r
815                 return(YES);\r
816         else\r
817                 return(CurHost.NoFullPath);\r
818 }\r
819 \r
820 \r
821 /*----- 接続しているユーザ名を返す --------------------------------------------\r
822 *\r
823 *       Parameter\r
824 *               なし\r
825 *\r
826 *       Return Value\r
827 *               char *ユーザ名\r
828 *----------------------------------------------------------------------------*/\r
829 \r
830 char *AskHostUserName(void)\r
831 {\r
832         return(CurHost.UserName);\r
833 }\r
834 \r
835 \r
836 /*----- 現在の設定をホストの設定にセットする ----------------------------------\r
837 *\r
838 *       Parameter\r
839 *               なし\r
840 *\r
841 *       Return Value\r
842 *               なし\r
843 *\r
844 *       Note\r
845 *               カレントディレクトリ、ソート方法をホストの設定にセットする\r
846 *----------------------------------------------------------------------------*/\r
847 \r
848 void SaveCurrentSetToHost(void)\r
849 {\r
850         int Host;\r
851         char LocDir[FMAX_PATH+1];\r
852         char HostDir[FMAX_PATH+1];\r
853 \r
854         if(TrnCtrlSocket != INVALID_SOCKET)\r
855         {\r
856                 if((Host = AskCurrentHost()) != HOSTNUM_NOENTRY)\r
857                 {\r
858                         CopyHostFromListInConnect(Host, &CurHost);\r
859                         if(CurHost.LastDir == YES)\r
860                         {\r
861                                 AskLocalCurDir(LocDir, FMAX_PATH);\r
862                                 AskRemoteCurDir(HostDir, FMAX_PATH);\r
863                                 SetHostDir(AskCurrentHost(), LocDir, HostDir);\r
864                         }\r
865                         SetHostSort(AskCurrentHost(), AskSortType(ITEM_LFILE), AskSortType(ITEM_LDIR), AskSortType(ITEM_RFILE), AskSortType(ITEM_RDIR));\r
866                 }\r
867         }\r
868         return;\r
869 }\r
870 \r
871 \r
872 /*----- 現在の設定をヒストリにセットする --------------------------------------\r
873 *\r
874 *       Parameter\r
875 *               なし\r
876 *\r
877 *       Return Value\r
878 *               なし\r
879 *----------------------------------------------------------------------------*/\r
880 \r
881 static void SaveCurrentSetToHistory(void)\r
882 {\r
883         char LocDir[FMAX_PATH+1];\r
884         char HostDir[FMAX_PATH+1];\r
885 \r
886         AskLocalCurDir(LocDir, FMAX_PATH);\r
887         AskRemoteCurDir(HostDir, FMAX_PATH);\r
888         strcpy(CurHost.LocalInitDir, LocDir);\r
889         strcpy(CurHost.RemoteInitDir, HostDir);\r
890 \r
891         CurHost.Sort = AskSortType(ITEM_LFILE) * 0x1000000 | AskSortType(ITEM_LDIR) * 0x10000 | AskSortType(ITEM_RFILE) * 0x100 | AskSortType(ITEM_RDIR);\r
892 \r
893         CurHost.KanjiCode = AskHostKanjiCode();\r
894         CurHost.KanaCnv = AskHostKanaCnv();\r
895 \r
896         CurHost.SyncMove = AskSyncMoveMode();\r
897 \r
898         AddHostToHistory(&CurHost, AskTransferType());\r
899         SetAllHistoryToMenu();\r
900 \r
901         return;\r
902 }\r
903 \r
904 \r
905 /*----- コマンドコントロールソケットの再接続 ----------------------------------\r
906 *\r
907 *       Parameter\r
908 *               なし\r
909 *\r
910 *       Return Value\r
911 *               int ステータス\r
912 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
913 *----------------------------------------------------------------------------*/\r
914 \r
915 int ReConnectCmdSkt(void)\r
916 {\r
917         int Sts;\r
918         SOCKET s;\r
919 \r
920 \r
921         // 同時接続対応\r
922 //      if(CmdCtrlSocket != TrnCtrlSocket)\r
923 //              do_closesocket(TrnCtrlSocket);\r
924 //      TrnCtrlSocket = INVALID_SOCKET;\r
925         s = TrnCtrlSocket;\r
926         TrnCtrlSocket = INVALID_SOCKET;\r
927         if(CmdCtrlSocket != s && s != INVALID_SOCKET)\r
928                 do_closesocket(s);\r
929 \r
930         // 同時接続対応\r
931 //      Sts = ReConnectSkt(&CmdCtrlSocket);\r
932         s = CmdCtrlSocket;\r
933         CmdCtrlSocket = INVALID_SOCKET;\r
934         Sts = ReConnectSkt(&s);\r
935         CmdCtrlSocket = s;\r
936 \r
937         TrnCtrlSocket = CmdCtrlSocket;\r
938 \r
939         return(Sts);\r
940 }\r
941 \r
942 \r
943 /*----- 転送コントロールソケットの再接続 --------------------------------------\r
944 *\r
945 *       Parameter\r
946 *               なし\r
947 *\r
948 *       Return Value\r
949 *               int ステータス\r
950 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
951 *----------------------------------------------------------------------------*/\r
952 \r
953 //int ReConnectTrnSkt(void)\r
954 //{\r
955 //      return(ReConnectSkt(&TrnCtrlSocket));\r
956 //}\r
957 // 同時接続対応\r
958 int ReConnectTrnSkt(SOCKET *Skt)\r
959 {\r
960         char Path[FMAX_PATH+1];\r
961         int Sts;\r
962 \r
963         Sts = FFFTP_FAIL;\r
964 \r
965         SetTaskMsg(MSGJPN003);\r
966 \r
967 //      DisableUserOpe();\r
968         /* 現在のソケットは切断 */\r
969         if(*Skt != INVALID_SOCKET)\r
970                 do_closesocket(*Skt);\r
971         /* 再接続 */\r
972         if((*Skt = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security)) != INVALID_SOCKET)\r
973         {\r
974 //              AskRemoteCurDir(Path, FMAX_PATH);\r
975 //              DoCWD(Path, YES, YES, YES);\r
976                 Sts = FFFTP_SUCCESS;\r
977         }\r
978         else\r
979                 SoundPlay(SND_ERROR);\r
980 \r
981 //      EnableUserOpe();\r
982         return(Sts);\r
983 }\r
984 \r
985 \r
986 /*----- 回線の再接続 ----------------------------------------------------------\r
987 *\r
988 *       Parameter\r
989 *               SOCKET *Skt : 接続したソケットを返すワーク\r
990 *\r
991 *       Return Value\r
992 *               int ステータス\r
993 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
994 *----------------------------------------------------------------------------*/\r
995 \r
996 static int ReConnectSkt(SOCKET *Skt)\r
997 {\r
998         char Path[FMAX_PATH+1];\r
999         int Sts;\r
1000 \r
1001         Sts = FFFTP_FAIL;\r
1002 \r
1003         SetTaskMsg(MSGJPN003);\r
1004 \r
1005         DisableUserOpe();\r
1006         /* 現在のソケットは切断 */\r
1007         if(*Skt != INVALID_SOCKET)\r
1008                 do_closesocket(*Skt);\r
1009         /* 再接続 */\r
1010         if((*Skt = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security)) != INVALID_SOCKET)\r
1011         {\r
1012                 AskRemoteCurDir(Path, FMAX_PATH);\r
1013                 DoCWD(Path, YES, YES, YES);\r
1014                 Sts = FFFTP_SUCCESS;\r
1015         }\r
1016         else\r
1017                 SoundPlay(SND_ERROR);\r
1018 \r
1019         EnableUserOpe();\r
1020         return(Sts);\r
1021 }\r
1022 \r
1023 \r
1024 /*----- コマンドコントロールソケットを返す ------------------------------------\r
1025 *\r
1026 *       Parameter\r
1027 *               なし\r
1028 *\r
1029 *       Return Value\r
1030 *               SOCKET コマンドコントロールソケット\r
1031 *----------------------------------------------------------------------------*/\r
1032 \r
1033 SOCKET AskCmdCtrlSkt(void)\r
1034 {\r
1035         return(CmdCtrlSocket);\r
1036 }\r
1037 \r
1038 \r
1039 /*----- 転送コントロールソケットを返す ----------------------------------------\r
1040 *\r
1041 *       Parameter\r
1042 *               なし\r
1043 *\r
1044 *       Return Value\r
1045 *               SOCKET 転送コントロールソケット\r
1046 *----------------------------------------------------------------------------*/\r
1047 \r
1048 SOCKET AskTrnCtrlSkt(void)\r
1049 {\r
1050         return(TrnCtrlSocket);\r
1051 }\r
1052 \r
1053 \r
1054 /*----- コマンド/転送コントロールソケットの共有を解除 ------------------------\r
1055 *\r
1056 *       Parameter\r
1057 *               なし\r
1058 *\r
1059 *       Return Value\r
1060 *               なし\r
1061 *----------------------------------------------------------------------------*/\r
1062 \r
1063 void SktShareProh(void)\r
1064 {\r
1065         if(CmdCtrlSocket == TrnCtrlSocket)\r
1066         {\r
1067 \r
1068 //SetTaskMsg("############### SktShareProh");\r
1069 \r
1070                 // 同時接続対応\r
1071                 // 転送スレッドがソケットを各自で用意\r
1072                 // TrnCtrlSocketはメインスレッド以外から使用されない\r
1073 //              CmdCtrlSocket = INVALID_SOCKET;\r
1074 //              ReConnectSkt(&CmdCtrlSocket);\r
1075         }\r
1076         return;\r
1077 }\r
1078 \r
1079 \r
1080 /*----- コマンド/転送コントロールソケットの共有が解除されているかチェック ----\r
1081 *\r
1082 *       Parameter\r
1083 *               なし\r
1084 *\r
1085 *       Return Value\r
1086 *               int ステータス\r
1087 *                       YES=共有解除/NO=共有\r
1088 *----------------------------------------------------------------------------*/\r
1089 \r
1090 int AskShareProh(void)\r
1091 {\r
1092         int Sts;\r
1093 \r
1094         Sts = YES;\r
1095         if(CmdCtrlSocket == TrnCtrlSocket)\r
1096                 Sts = NO;\r
1097 \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 *               なし\r
1109 *----------------------------------------------------------------------------*/\r
1110 \r
1111 void DisconnectProc(void)\r
1112 {\r
1113 \r
1114 //SetTaskMsg("############### Disconnect Cmd=%x, Trn=%x", CmdCtrlSocket,TrnCtrlSocket);\r
1115 \r
1116         if((CmdCtrlSocket != INVALID_SOCKET) && (CmdCtrlSocket != TrnCtrlSocket))\r
1117         {\r
1118                 DoQUIT(CmdCtrlSocket);\r
1119                 DoClose(CmdCtrlSocket);\r
1120         }\r
1121 \r
1122         if(TrnCtrlSocket != INVALID_SOCKET)\r
1123         {\r
1124                 DoQUIT(TrnCtrlSocket);\r
1125                 DoClose(TrnCtrlSocket);\r
1126 \r
1127                 SaveCurrentSetToHistory();\r
1128 \r
1129                 EraseRemoteDirForWnd();\r
1130                 SetTaskMsg(MSGJPN004);\r
1131         }\r
1132 \r
1133         TrnCtrlSocket = INVALID_SOCKET;\r
1134         CmdCtrlSocket = INVALID_SOCKET;\r
1135 \r
1136         DispWindowTitle();\r
1137         MakeButtonsFocus();\r
1138         ClearBookMark();\r
1139 \r
1140         return;\r
1141 }\r
1142 \r
1143 \r
1144 /*----- ソケットが強制切断されたときの処理 ------------------------------------\r
1145 *\r
1146 *       Parameter\r
1147 *               なし\r
1148 *\r
1149 *       Return Value\r
1150 *               なし\r
1151 *----------------------------------------------------------------------------*/\r
1152 \r
1153 void DisconnectSet(void)\r
1154 {\r
1155         CmdCtrlSocket = INVALID_SOCKET;\r
1156         TrnCtrlSocket = INVALID_SOCKET;\r
1157 \r
1158         EraseRemoteDirForWnd();\r
1159         DispWindowTitle();\r
1160         MakeButtonsFocus();\r
1161         SetTaskMsg(MSGJPN005);\r
1162         return;\r
1163 }\r
1164 \r
1165 \r
1166 /*----- ホストに接続中かどうかを返す ------------------------------------------\r
1167 *\r
1168 *       Parameter\r
1169 *               なし\r
1170 *\r
1171 *       Return Value\r
1172 *               int ステータス (YES/NO)\r
1173 *----------------------------------------------------------------------------*/\r
1174 \r
1175 int AskConnecting(void)\r
1176 {\r
1177         int Sts;\r
1178 \r
1179         Sts = NO;\r
1180         if(TrnCtrlSocket != INVALID_SOCKET)\r
1181                 Sts = YES;\r
1182 \r
1183         return(Sts);\r
1184 }\r
1185 \r
1186 \r
1187 /*----- ホストへ接続する ------------------------------------------------------\r
1188 *\r
1189 *       Parameter\r
1190 *               char *Host : ホスト名\r
1191 *               char *User : ユーザ名\r
1192 *               char *Pass : パスワード\r
1193 *               char *Acct : アカウント\r
1194 *               int Port : ポート\r
1195 *               int Fwall : FireWallを使うかどうか (YES/NO)\r
1196 *               int SavePass : パスワードを再入力した時に保存するかどうか (YES/NO)\r
1197 *               int Security : セキュリティ (SECURITY_xxx, MDx)\r
1198 *\r
1199 *       Return Value\r
1200 *               SOCKET ソケット\r
1201 *\r
1202 *       Note\r
1203 *               ホスト名、ユーザ名、パスワードが指定されていなかったときは、接続に使用\r
1204 *               したものをコピーしてかえす\r
1205 *                       char *Host : ホスト名\r
1206 *                       char *User : ユーザ名\r
1207 *                       char *Pass : パスワード\r
1208 *                       char *Acct : アカウント\r
1209 *\r
1210 *               FireWallは次のように動作する\r
1211 *                       TYPE1   Connect fire → USER user(f) → PASS pass(f) → SITE host → USER user(h) →      PASS pass(h) → ACCT acct\r
1212 *                       TYPE2   Connect fire → USER user(f) → PASS pass(f) →              USER user(h)@host → PASS pass(h) → ACCT acct\r
1213 *                       TYPE3   Connect fire →                                              USER user(h)@host → PASS pass(h) → ACCT acct\r
1214 *                       TYPE4   Connect fire →                                 OPEN host → USER user(h) →      PASS pass(h) → ACCT acct\r
1215 *                       TYPE5   SOCKS4\r
1216 *                       none    Connect host →                                              USER user(h) →      PASS pass(h) → ACCT acct\r
1217 *----------------------------------------------------------------------------*/\r
1218 \r
1219 static SOCKET DoConnect(char *Host, char *User, char *Pass, char *Acct, int Port, int Fwall, int SavePass, int Security)\r
1220 {\r
1221         int Sts;\r
1222         int Flg;\r
1223         int Anony;\r
1224         SOCKET ContSock;\r
1225         char Buf[1024];\r
1226         char Reply[1024];\r
1227         int Continue;\r
1228         int ReInPass;\r
1229         char *Tmp;\r
1230         int HostPort;\r
1231         static const char *SiteTbl[4] = { "SITE", "site", "OPEN", "open" };\r
1232         char TmpBuf[ONELINE_BUF_SIZE];\r
1233         struct linger LingerOpt;\r
1234 \r
1235         if(Fwall == YES)\r
1236                 Fwall = FwallType;\r
1237         else\r
1238                 Fwall = FWALL_NONE;\r
1239 \r
1240         TryConnect = YES;\r
1241         CancelFlg = NO;\r
1242 #if 0\r
1243 //      WSASetBlockingHook(BlkHookFnc);\r
1244 #endif\r
1245 \r
1246         ContSock = INVALID_SOCKET;\r
1247 \r
1248         HostPort = Port;\r
1249         Tmp = Host;\r
1250         if(((Fwall >= FWALL_FU_FP_SITE) && (Fwall <= FWALL_OPEN)) ||\r
1251            (Fwall == FWALL_SIDEWINDER) ||\r
1252            (Fwall == FWALL_FU_FP))\r
1253         {\r
1254                 Tmp = FwallHost;\r
1255                 Port = FwallPort;\r
1256         }\r
1257 \r
1258         if(strlen(Tmp) != 0)\r
1259         {\r
1260                 if((ContSock = connectsock(Tmp, Port, "", &CancelFlg)) != INVALID_SOCKET)\r
1261                 {\r
1262                         // バッファを無効\r
1263 #ifdef DISABLE_CONTROL_NETWORK_BUFFERS\r
1264                         int BufferSize = 0;\r
1265                         setsockopt(ContSock, SOL_SOCKET, SO_SNDBUF, (char*)&BufferSize, sizeof(int));\r
1266                         setsockopt(ContSock, SOL_SOCKET, SO_RCVBUF, (char*)&BufferSize, sizeof(int));\r
1267 #endif\r
1268                         while((Sts = ReadReplyMessage(ContSock, Buf, 1024, &CancelFlg, TmpBuf) / 100) == FTP_PRELIM)\r
1269                                 ;\r
1270 \r
1271                         if(Sts == FTP_COMPLETE)\r
1272                         {\r
1273                                 Flg = 1;\r
1274                                 if(setsockopt(ContSock, SOL_SOCKET, SO_OOBINLINE, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
1275                                         ReportWSError("setsockopt", WSAGetLastError());\r
1276                                 // データ転送用ソケットのTCP遅延転送が無効されているので念のため\r
1277                                 if(setsockopt(ContSock, IPPROTO_TCP, TCP_NODELAY, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
1278                                         ReportWSError("setsockopt", WSAGetLastError());\r
1279 #pragma aaa\r
1280                                 Flg = 1;\r
1281                                 if(setsockopt(ContSock, SOL_SOCKET, SO_KEEPALIVE, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
1282                                         ReportWSError("setsockopt", WSAGetLastError());\r
1283                                 LingerOpt.l_onoff = 1;\r
1284                                 LingerOpt.l_linger = 90;\r
1285                                 if(setsockopt(ContSock, SOL_SOCKET, SO_LINGER, (LPSTR)&LingerOpt, sizeof(LingerOpt)) == SOCKET_ERROR)\r
1286                                         ReportWSError("setsockopt", WSAGetLastError());\r
1287 ///////\r
1288 \r
1289 \r
1290                                 /*===== 認証を行なう =====*/\r
1291 \r
1292                                 Sts = FTP_COMPLETE;\r
1293                                 if((Fwall == FWALL_FU_FP_SITE) ||\r
1294                                    (Fwall == FWALL_FU_FP_USER) ||\r
1295                                    (Fwall == FWALL_FU_FP))\r
1296                                 {\r
1297                                         if((Sts = command(ContSock, Reply, &CancelFlg, "USER %s", FwallUser) / 100) == FTP_CONTINUE)\r
1298                                         {\r
1299                                                 CheckOneTimePassword(FwallPass, Reply, FwallSecurity);\r
1300                                                 Sts = command(ContSock, NULL, &CancelFlg, "PASS %s", Reply) / 100;\r
1301                                         }\r
1302                                 }\r
1303                                 else if(Fwall == FWALL_SIDEWINDER)\r
1304                                 {\r
1305                                         Sts = command(ContSock, Reply, &CancelFlg, "USER %s:%s%c%s", FwallUser, FwallPass, FwallDelimiter, Host) / 100;\r
1306                                 }\r
1307                                 if((Sts != FTP_COMPLETE) && (Sts != FTP_CONTINUE))\r
1308                                 {\r
1309                                         SetTaskMsg(MSGJPN006);\r
1310                                         DoClose(ContSock);\r
1311                                         ContSock = INVALID_SOCKET;\r
1312                                 }\r
1313                                 else\r
1314                                 {\r
1315                                         if((Fwall == FWALL_FU_FP_SITE) || (Fwall == FWALL_OPEN))\r
1316                                         {\r
1317                                                 Flg = 0;\r
1318                                                 if(Fwall == FWALL_OPEN)\r
1319                                                         Flg = 2;\r
1320                                                 if(FwallLower == YES)\r
1321                                                         Flg++;\r
1322 \r
1323                                                 if(HostPort == PORT_NOR)\r
1324                                                         Sts = command(ContSock, NULL, &CancelFlg, "%s %s", SiteTbl[Flg], Host) / 100;\r
1325                                                 else\r
1326                                                         Sts = command(ContSock, NULL, &CancelFlg, "%s %s %d", SiteTbl[Flg], Host, HostPort) / 100;\r
1327                                         }\r
1328 \r
1329                                         if((Sts != FTP_COMPLETE) && (Sts != FTP_CONTINUE))\r
1330                                         {\r
1331                                                 SetTaskMsg(MSGJPN007, Host);\r
1332                                                 DoClose(ContSock);\r
1333                                                 ContSock = INVALID_SOCKET;\r
1334                                         }\r
1335                                         else\r
1336                                         {\r
1337                                                 Anony = NO;\r
1338                                                 if((strlen(User) != 0) || \r
1339                                                    (InputDialogBox(username_dlg, GetMainHwnd(), NULL, User, USER_NAME_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
1340                                                 {\r
1341                                                         if(Anony == YES)\r
1342                                                         {\r
1343                                                                 strcpy(User, "anonymous");\r
1344                                                                 strcpy(Pass, UserMailAdrs);\r
1345                                                         }\r
1346 \r
1347                                                         if((Fwall == FWALL_FU_FP_USER) || (Fwall == FWALL_USER))\r
1348                                                         {\r
1349                                                                 if(HostPort == PORT_NOR)\r
1350                                                                         sprintf(Buf, "%s%c%s", User, FwallDelimiter, Host);\r
1351                                                                 else\r
1352                                                                         sprintf(Buf, "%s%c%s %d", User, FwallDelimiter, Host, HostPort);\r
1353                                                         }\r
1354                                                         else\r
1355                                                                 strcpy(Buf, User);\r
1356 \r
1357                                                         // FTPES対応\r
1358                                                         // 2回以上呼ばれる事があるため既にFTPESで接続していても再確認\r
1359                                                         if(CurHost.CryptMode == CRYPT_NONE || CurHost.CryptMode == CRYPT_FTPES)\r
1360                                                         {\r
1361                                                                 if(IsOpenSSLLoaded() && CurHost.UseFTPES == YES && (Sts = command(ContSock, Reply, &CancelFlg, "AUTH TLS")) == 234)\r
1362                                                                 {\r
1363                                                                         // SSLに切り替え\r
1364                                                                         SetTaskMsg(MSGJPN315);\r
1365                                                                         CurHost.CryptMode = CRYPT_FTPES;\r
1366                                                                         if(AttachSSL(ContSock))\r
1367                                                                         {\r
1368                                                                                 if((Sts = command(ContSock, Reply, &CancelFlg, "PBSZ 0")) == 200)\r
1369                                                                                 {\r
1370                                                                                         if((Sts = command(ContSock, Reply, &CancelFlg, "PROT P")) == 200)\r
1371                                                                                         {\r
1372                                                                                         }\r
1373                                                                                         else\r
1374                                                                                                 Sts = FTP_ERROR;\r
1375                                                                                 }\r
1376                                                                                 else\r
1377                                                                                         Sts = FTP_ERROR;\r
1378                                                                         }\r
1379                                                                         else\r
1380                                                                                 Sts = FTP_ERROR;\r
1381                                                                 }\r
1382                                                                 else\r
1383                                                                 {\r
1384                                                                         // 暗号化なし\r
1385                                                                         CurHost.CryptMode = CRYPT_NONE;\r
1386                                                                         SetTaskMsg(MSGJPN314);\r
1387                                                                 }\r
1388                                                         }\r
1389 \r
1390                                                         ReInPass = NO;\r
1391                                                         do\r
1392                                                         {\r
1393                                                                 Continue = NO;\r
1394                                                                 if((Sts = command(ContSock, Reply, &CancelFlg, "USER %s", Buf) / 100) == FTP_CONTINUE)\r
1395                                                                 {\r
1396                                                                         if((strlen(Pass) != 0) || \r
1397                                                                            (InputDialogBox(passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
1398                                                                         {\r
1399                                                                                 CheckOneTimePassword(Pass, Reply, Security);\r
1400 \r
1401                                                                                 /* パスワードがスペース1個の時はパスワードの実体なしとする */\r
1402                                                                                 if(strcmp(Reply, " ") == 0)\r
1403                                                                                         strcpy(Reply, "");\r
1404 \r
1405                                                                                 Sts = command(ContSock, NULL, &CancelFlg, "PASS %s", Reply) / 100;\r
1406                                                                                 if(Sts == FTP_ERROR)\r
1407                                                                                 {\r
1408                                                                                         strcpy(Pass, "");\r
1409                                                                                         if(InputDialogBox(re_passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)\r
1410                                                                                                 Continue = YES;\r
1411                                                                                         else\r
1412                                                                                                 DoPrintf("No password specified.");\r
1413                                                                                         ReInPass = YES;\r
1414                                                                                 }\r
1415                                                                                 else if(Sts == FTP_CONTINUE)\r
1416                                                                                 {\r
1417                                                                                         if((strlen(Acct) != 0) || \r
1418                                                                                            (InputDialogBox(account_dlg, GetMainHwnd(), NULL, Acct, ACCOUNT_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
1419                                                                                         {\r
1420                                                                                                 Sts = command(ContSock, NULL, &CancelFlg, "ACCT %s", Acct) / 100;\r
1421                                                                                         }\r
1422                                                                                         else\r
1423                                                                                                 DoPrintf("No account specified");\r
1424                                                                                 }\r
1425                                                                         }\r
1426                                                                         else\r
1427                                                                         {\r
1428                                                                                 Sts = FTP_ERROR;\r
1429                                                                                 DoPrintf("No password specified.");\r
1430                                                                         }\r
1431                                                                 }\r
1432                                                         }\r
1433                                                         while(Continue == YES);\r
1434                                                 }\r
1435                                                 else\r
1436                                                 {\r
1437                                                         Sts = FTP_ERROR;\r
1438                                                         DoPrintf("No user name specified");\r
1439                                                 }\r
1440 \r
1441                                                 if(Sts != FTP_COMPLETE)\r
1442                                                 {\r
1443                                                         SetTaskMsg(MSGJPN008, Host);\r
1444                                                         DoClose(ContSock);\r
1445                                                         ContSock = INVALID_SOCKET;\r
1446                                                 }\r
1447                                                 else if((SavePass == YES) && (ReInPass == YES))\r
1448                                                 {\r
1449                                                         if(DialogBox(GetFtpInst(), MAKEINTRESOURCE(savepass_dlg), GetMainHwnd(), ExeEscDialogProc) == YES)\r
1450                                                                 SetHostPassword(AskCurrentHost(), Pass);\r
1451                                                 }\r
1452                                         }\r
1453                                 }\r
1454                         }\r
1455                         else\r
1456                         {\r
1457 //#pragma aaa\r
1458                                 SetTaskMsg(MSGJPN009/*"接続できません(1) %x", ContSock*/);\r
1459                                 DoClose(ContSock);\r
1460                                 ContSock = INVALID_SOCKET;\r
1461                         }\r
1462                 }\r
1463         }\r
1464         else\r
1465         {\r
1466 \r
1467                 if(((Fwall >= FWALL_FU_FP_SITE) && (Fwall <= FWALL_OPEN)) ||\r
1468                    (Fwall == FWALL_FU_FP))\r
1469                         SetTaskMsg(MSGJPN010);\r
1470                 else\r
1471                         SetTaskMsg(MSGJPN011);\r
1472         }\r
1473 \r
1474 #if 0\r
1475 //      WSAUnhookBlockingHook();\r
1476 #endif\r
1477         TryConnect = NO;\r
1478 \r
1479         return(ContSock);\r
1480 }\r
1481 \r
1482 \r
1483 /*----- ワンタイムパスワードのチェック ----------------------------------------\r
1484 *\r
1485 *       Parameter\r
1486 *               chat *Pass : パスワード/パスフレーズ\r
1487 *               char *Reply : USERコマンドを送ったあとのリプライ文字列\r
1488 *                                               /PASSコマンドで送るパスワードを返すバッファ\r
1489 *               int Type : タイプ (SECURITY_xxx, MDx)\r
1490 *\r
1491 *       Return Value\r
1492 *               int ステータス\r
1493 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
1494 *\r
1495 *       Note\r
1496 *               ワンタイムパスワードでない時はPassをそのままReplyにコピー\r
1497 *----------------------------------------------------------------------------*/\r
1498 \r
1499 static int CheckOneTimePassword(char *Pass, char *Reply, int Type)\r
1500 {\r
1501         int Sts;\r
1502         char *Pos;\r
1503         int Seq;\r
1504         char Seed[MAX_SEED_LEN+1];\r
1505         int i;\r
1506 \r
1507         Sts = FFFTP_SUCCESS;\r
1508         Pos = NULL;\r
1509 \r
1510         if(Type == SECURITY_AUTO)\r
1511         {\r
1512                 if((Pos = stristr(Reply, "otp-md5")) != NULL)\r
1513                 {\r
1514                         Type = MD5;\r
1515                         SetTaskMsg(MSGJPN012);\r
1516                 }\r
1517                 else if((Pos = stristr(Reply, "otp-sha1")) != NULL)\r
1518                 {\r
1519                         Type = SHA1;\r
1520                         SetTaskMsg(MSGJPN013);\r
1521                 }\r
1522                 else if(((Pos = stristr(Reply, "otp-md4")) != NULL) || ((Pos = stristr(Reply, "s/key")) != NULL))\r
1523                 {\r
1524                         Type = MD4;\r
1525                         SetTaskMsg(MSGJPN014);\r
1526                 }\r
1527         }\r
1528         else\r
1529                 Pos = GetNextField(Reply);\r
1530 \r
1531         if((Type == MD4) || (Type == MD5) || (Type == SHA1))\r
1532         {\r
1533                 /* シーケンス番号を見つけるループ */\r
1534                 DoPrintf("Analize OTP");\r
1535                 DoPrintf("%s", Pos);\r
1536                 Sts = FFFTP_FAIL;\r
1537                 while((Pos = GetNextField(Pos)) != NULL)\r
1538                 {\r
1539                         if(IsDigit(*Pos))\r
1540                         {\r
1541                                 Seq = atoi(Pos);\r
1542                                 DoPrintf("Sequence=%d", Seq);\r
1543 \r
1544                                 /* Seed */\r
1545                                 if((Pos = GetNextField(Pos)) != NULL)\r
1546                                 {\r
1547                                         if(GetOneField(Pos, Seed, MAX_SEED_LEN) == FFFTP_SUCCESS)\r
1548                                         {\r
1549                                                 /* Seedは英数字のみ有効とする */\r
1550                                                 for(i = strlen(Seed)-1; i >= 0; i--)\r
1551                                                 {\r
1552                                                         if((IsAlpha(Seed[i]) == 0) && (IsDigit(Seed[i]) == 0))\r
1553                                                                 Seed[i] = NUL;\r
1554                                                 }\r
1555                                                 if(strlen(Seed) > 0)\r
1556                                                 {\r
1557                                                         DoPrintf("Seed=%s", Seed);\r
1558                                                         Make6WordPass(Seq, Seed, Pass, Type, Reply);\r
1559                                                         DoPrintf("Response=%s", Reply);\r
1560 \r
1561                                                         /* シーケンス番号のチェックと警告 */\r
1562                                                         if(Seq <= 10)\r
1563                                                                 DialogBox(GetFtpInst(), MAKEINTRESOURCE(otp_notify_dlg), GetMainHwnd(), ExeEscDialogProc);\r
1564 \r
1565                                                         Sts = FFFTP_SUCCESS;\r
1566                                                 }\r
1567                                         }\r
1568                                 }\r
1569                                 break;\r
1570                         }\r
1571                 }\r
1572 \r
1573                 if(Sts == FFFTP_FAIL)\r
1574                         SetTaskMsg(MSGJPN015);\r
1575         }\r
1576         else\r
1577         {\r
1578                 strcpy(Reply, Pass);\r
1579                 DoPrintf("No OTP used.");\r
1580         }\r
1581         return(Sts);\r
1582 }\r
1583 \r
1584 \r
1585 \r
1586 \r
1587 \r
1588 \r
1589 \r
1590 \r
1591 \r
1592 \r
1593 \r
1594 \r
1595 \r
1596 \r
1597 /*----- ソケットを接続する ----------------------------------------------------\r
1598 *\r
1599 *       Parameter\r
1600 *               char *host : ホスト名\r
1601 *               int port : ポート番号\r
1602 *               char *PreMsg : メッセージの前半部分\r
1603 *\r
1604 *       Return Value\r
1605 *               SOCKET ソケット\r
1606 *----------------------------------------------------------------------------*/\r
1607 \r
1608 SOCKET connectsock(char *host, int port, char *PreMsg, int *CancelCheckWork)\r
1609 {\r
1610         struct sockaddr_in saSockAddr;\r
1611         char HostEntry[MAXGETHOSTSTRUCT];\r
1612         struct hostent *pHostEntry;\r
1613         SOCKET sSocket;\r
1614         int Len;\r
1615         int Fwall;\r
1616         SOCKS4CMD Socks4Cmd;\r
1617         SOCKS4REPLY Socks4Reply;\r
1618         SOCKS5REQUEST Socks5Cmd;\r
1619         SOCKS5REPLY Socks5Reply;\r
1620 \r
1621         //////////////////////////////\r
1622         // ホスト名解決と接続の準備\r
1623         //////////////////////////////\r
1624 \r
1625         Fwall = FWALL_NONE;\r
1626         if(AskHostFireWall() == YES)\r
1627                 Fwall = FwallType;\r
1628 \r
1629         sSocket = INVALID_SOCKET;\r
1630 \r
1631         UseIPadrs = YES;\r
1632         strcpy(DomainName, host);\r
1633         memset(&CurSockAddr, 0, sizeof(CurSockAddr));\r
1634         CurSockAddr.sin_port = htons((u_short)port);\r
1635         CurSockAddr.sin_family = AF_INET;\r
1636         if((CurSockAddr.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE)\r
1637         {\r
1638                 // ホスト名が指定された\r
1639                 // ホスト名からアドレスを求める\r
1640                 if(((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER)) &&\r
1641                    (FwallResolv == YES))\r
1642                 {\r
1643                         // ホスト名解決はSOCKSサーバに任せる\r
1644                         pHostEntry = NULL;\r
1645                 }\r
1646                 else\r
1647                 {\r
1648                         // アドレスを取得\r
1649                         SetTaskMsg(MSGJPN016, DomainName);\r
1650                         pHostEntry = do_gethostbyname(host, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork);\r
1651                 }\r
1652 \r
1653                 if(pHostEntry != NULL)\r
1654                 {\r
1655                         memcpy((char *)&CurSockAddr.sin_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
1656                         SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet_ntoa(CurSockAddr.sin_addr), ntohs(CurSockAddr.sin_port));\r
1657                 }\r
1658                 else\r
1659                 {\r
1660                         if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
1661                         {\r
1662                                 UseIPadrs = NO;\r
1663                                 SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddr.sin_port));\r
1664                         }\r
1665                         else\r
1666                         {\r
1667                                 SetTaskMsg(MSGJPN019, host);\r
1668                                 return(INVALID_SOCKET);\r
1669                         }\r
1670                 }\r
1671         }\r
1672         else\r
1673                 SetTaskMsg(MSGJPN020, PreMsg, inet_ntoa(CurSockAddr.sin_addr), ntohs(CurSockAddr.sin_port));\r
1674 \r
1675         if((Fwall == FWALL_SOCKS4) || (Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
1676         {\r
1677                 // SOCKSを使う\r
1678                 // SOCKSに接続する準備\r
1679                 if(Fwall == FWALL_SOCKS4)\r
1680                 {\r
1681                         Socks4Cmd.Ver = SOCKS4_VER;\r
1682                         Socks4Cmd.Cmd = SOCKS4_CMD_CONNECT;\r
1683                         Socks4Cmd.Port = CurSockAddr.sin_port;\r
1684                         Socks4Cmd.AdrsInt = CurSockAddr.sin_addr.s_addr;\r
1685                         strcpy(Socks4Cmd.UserID, FwallUser);\r
1686                         Len = offsetof(SOCKS4CMD, UserID) + strlen(FwallUser) + 1;\r
1687                 }\r
1688                 else\r
1689                 {\r
1690                         Len = Socks5MakeCmdPacket(&Socks5Cmd, SOCKS5_CMD_CONNECT, UseIPadrs, CurSockAddr.sin_addr.s_addr, DomainName, CurSockAddr.sin_port);\r
1691                 }\r
1692 \r
1693                 memset(&SocksSockAddr, 0, sizeof(SocksSockAddr));\r
1694                 if((SocksSockAddr.sin_addr.s_addr = inet_addr(FwallHost)) == INADDR_NONE)\r
1695                 {\r
1696                         if((pHostEntry = do_gethostbyname(FwallHost, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork)) != NULL)\r
1697                                 memcpy((char *)&SocksSockAddr.sin_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
1698                         else\r
1699                         {\r
1700                                 SetTaskMsg(MSGJPN021, FwallHost);\r
1701                                 return INVALID_SOCKET;\r
1702                         }\r
1703                 }\r
1704                 SocksSockAddr.sin_port = htons((u_short)FwallPort);\r
1705                 SocksSockAddr.sin_family = AF_INET;\r
1706                 SetTaskMsg(MSGJPN022, inet_ntoa(SocksSockAddr.sin_addr), ntohs(SocksSockAddr.sin_port));\r
1707                 // connectで接続する先はSOCKSサーバ\r
1708                 memcpy(&saSockAddr, &SocksSockAddr, sizeof(SocksSockAddr));\r
1709         }\r
1710         else\r
1711         {\r
1712                 // connectで接続するのは接続先のホスト\r
1713                 memcpy(&saSockAddr, &CurSockAddr, sizeof(CurSockAddr));\r
1714         }\r
1715 \r
1716         /////////////\r
1717         // 接続実行\r
1718         /////////////\r
1719 \r
1720         if((sSocket = do_socket(AF_INET, SOCK_STREAM, TCP_PORT)) != INVALID_SOCKET)\r
1721         {\r
1722                 if(do_connect(sSocket, (struct sockaddr *)&saSockAddr, sizeof(saSockAddr), CancelCheckWork) != SOCKET_ERROR)\r
1723                 {\r
1724                         if(Fwall == FWALL_SOCKS4)\r
1725                         {\r
1726                                 Socks4Reply.Result = -1;\r
1727                                 if((SocksSendCmd(sSocket, &Socks4Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
1728                                    (Socks4GetCmdReply(sSocket, &Socks4Reply) != FFFTP_SUCCESS) || \r
1729                                    (Socks4Reply.Result != SOCKS4_RES_OK))\r
1730                                 {\r
1731                                         SetTaskMsg(MSGJPN023, Socks4Reply.Result);\r
1732                                         DoClose(sSocket);\r
1733                                         sSocket = INVALID_SOCKET;\r
1734                                 }\r
1735                         }\r
1736                         else if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
1737                         {\r
1738                                 if(Socks5SelMethod(sSocket, CancelCheckWork) == FFFTP_FAIL)\r
1739                                 {\r
1740                                         DoClose(sSocket);\r
1741                                         sSocket = INVALID_SOCKET;\r
1742                                 }\r
1743 \r
1744                                 Socks5Reply.Result = -1;\r
1745                                 if((SocksSendCmd(sSocket, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
1746                                    (Socks5GetCmdReply(sSocket, &Socks5Reply) != FFFTP_SUCCESS) || \r
1747                                    (Socks5Reply.Result != SOCKS5_RES_OK))\r
1748                                 {\r
1749                                         SetTaskMsg(MSGJPN024, Socks5Reply.Result);\r
1750                                         DoClose(sSocket);\r
1751                                         sSocket = INVALID_SOCKET;\r
1752                                 }\r
1753 \r
1754                         }\r
1755 \r
1756                         if(sSocket != INVALID_SOCKET)\r
1757                                 SetTaskMsg(MSGJPN025);\r
1758                 }\r
1759                 else\r
1760                 {\r
1761 //#pragma aaa\r
1762                         SetTaskMsg(MSGJPN026/*"接続できません(2) %x", sSocket*/);\r
1763                         DoClose(sSocket);\r
1764                         sSocket = INVALID_SOCKET;\r
1765                 }\r
1766         }\r
1767         else\r
1768                 SetTaskMsg(MSGJPN027);\r
1769 \r
1770         return(sSocket);\r
1771 }\r
1772 \r
1773 \r
1774 /*----- リッスンソケットを取得 ------------------------------------------------\r
1775 *\r
1776 *       Parameter\r
1777 *               SOCKET ctrl_skt : コントロールソケット\r
1778 *\r
1779 *       Return Value\r
1780 *               SOCKET リッスンソケット\r
1781 *----------------------------------------------------------------------------*/\r
1782 \r
1783 SOCKET GetFTPListenSocket(SOCKET ctrl_skt, int *CancelCheckWork)\r
1784 {\r
1785     SOCKET listen_skt;\r
1786     int iLength;\r
1787     char *a,*p;\r
1788         struct sockaddr_in saCtrlAddr;\r
1789         struct sockaddr_in saTmpAddr;\r
1790         SOCKS4CMD Socks4Cmd;\r
1791         SOCKS4REPLY Socks4Reply;\r
1792         SOCKS5REQUEST Socks5Cmd;\r
1793         SOCKS5REPLY Socks5Reply;\r
1794 \r
1795         int Len;\r
1796         int Fwall;\r
1797 \r
1798         Fwall = FWALL_NONE;\r
1799         if(AskHostFireWall() == YES)\r
1800                 Fwall = FwallType;\r
1801 \r
1802         if((listen_skt = do_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) != INVALID_SOCKET)\r
1803         {\r
1804                 if(Fwall == FWALL_SOCKS4)\r
1805                 {\r
1806                         /*===== SOCKS4を使う =====*/\r
1807                         DoPrintf("Use SOCKS4 BIND");\r
1808                         if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddr, sizeof(SocksSockAddr), CancelCheckWork) != SOCKET_ERROR)\r
1809                         {\r
1810                                 Socks4Cmd.Ver = SOCKS4_VER;\r
1811                                 Socks4Cmd.Cmd = SOCKS4_CMD_BIND;\r
1812                                 Socks4Cmd.Port = CurSockAddr.sin_port;\r
1813                                 Socks4Cmd.AdrsInt = CurSockAddr.sin_addr.s_addr;\r
1814                                 strcpy(Socks4Cmd.UserID, FwallUser);\r
1815                                 Len = offsetof(SOCKS4CMD, UserID) + strlen(FwallUser) + 1;\r
1816 \r
1817                                 Socks4Reply.Result = -1;\r
1818                                 if((SocksSendCmd(listen_skt, &Socks4Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
1819                                    (Socks4GetCmdReply(listen_skt, &Socks4Reply) != FFFTP_SUCCESS) || \r
1820                                    (Socks4Reply.Result != SOCKS4_RES_OK))\r
1821                                 {\r
1822                                         SetTaskMsg(MSGJPN028, Socks4Reply.Result);\r
1823                                         DoClose(listen_skt);\r
1824                                         listen_skt = INVALID_SOCKET;\r
1825                                 }\r
1826 \r
1827                                 if(Socks4Reply.AdrsInt == 0)\r
1828                                         Socks4Reply.AdrsInt = SocksSockAddr.sin_addr.s_addr;\r
1829 \r
1830                                 a = (char *)&Socks4Reply.AdrsInt;\r
1831                                 p = (char *)&Socks4Reply.Port;\r
1832                         }\r
1833                 }\r
1834                 else if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
1835                 {\r
1836                         /*===== SOCKS5を使う =====*/\r
1837                         DoPrintf("Use SOCKS5 BIND");\r
1838                         if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddr, sizeof(SocksSockAddr), CancelCheckWork) != SOCKET_ERROR)\r
1839                         {\r
1840                                 if(Socks5SelMethod(listen_skt, CancelCheckWork) == FFFTP_FAIL)\r
1841                                 {\r
1842                                         DoClose(listen_skt);\r
1843                                         listen_skt = INVALID_SOCKET;\r
1844                                         return(listen_skt);\r
1845                                 }\r
1846 \r
1847                                 Len = Socks5MakeCmdPacket(&Socks5Cmd, SOCKS5_CMD_BIND, UseIPadrs, CurSockAddr.sin_addr.s_addr, DomainName, CurSockAddr.sin_port);\r
1848 \r
1849                                 Socks5Reply.Result = -1;\r
1850                                 if((SocksSendCmd(listen_skt, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
1851                                    (Socks5GetCmdReply(listen_skt, &Socks5Reply) != FFFTP_SUCCESS) || \r
1852                                    (Socks5Reply.Result != SOCKS5_RES_OK))\r
1853                                 {\r
1854                                         SetTaskMsg(MSGJPN029, Socks5Reply.Result);\r
1855                                         DoClose(listen_skt);\r
1856                                         listen_skt = INVALID_SOCKET;\r
1857                                 }\r
1858 \r
1859                                 if(Socks5Reply.AdrsInt == 0)\r
1860                                         Socks5Reply.AdrsInt = SocksSockAddr.sin_addr.s_addr;\r
1861 \r
1862                                 a = (char *)&Socks5Reply.AdrsInt;\r
1863                                 p = (char *)&Socks5Reply.Port;\r
1864                         }\r
1865                 }\r
1866                 else\r
1867                 {\r
1868                         /*===== SOCKSを使わない =====*/\r
1869                         DoPrintf("Use normal BIND");\r
1870                         saCtrlAddr.sin_port = htons(0);\r
1871                         saCtrlAddr.sin_family = AF_INET;\r
1872                         saCtrlAddr.sin_addr.s_addr = 0;\r
1873 \r
1874                         if(bind(listen_skt, (struct sockaddr *)&saCtrlAddr, sizeof(struct sockaddr)) != SOCKET_ERROR)\r
1875                         {\r
1876                                 iLength = sizeof(saCtrlAddr);\r
1877                                 if(getsockname(listen_skt, (struct sockaddr *)&saCtrlAddr, &iLength) != SOCKET_ERROR)\r
1878                                 {\r
1879                                         if(do_listen(listen_skt, 1) == 0)\r
1880                                         {\r
1881                                                 iLength = sizeof(saTmpAddr);\r
1882                                                 if(getsockname(ctrl_skt, (struct sockaddr *)&saTmpAddr, &iLength) == SOCKET_ERROR)\r
1883                                                         ReportWSError("getsockname", WSAGetLastError());\r
1884 \r
1885                                                 a = (char *)&saTmpAddr.sin_addr;\r
1886                                                 p = (char *)&saCtrlAddr.sin_port;\r
1887                                         }\r
1888                                         else\r
1889                                         {\r
1890                                                 ReportWSError("listen", WSAGetLastError());\r
1891                                                 do_closesocket(listen_skt);\r
1892                                                 listen_skt = INVALID_SOCKET;\r
1893                                         }\r
1894                                 }\r
1895                                 else\r
1896                                 {\r
1897                                         ReportWSError("getsockname", WSAGetLastError());\r
1898                                         do_closesocket(listen_skt);\r
1899                                         listen_skt = INVALID_SOCKET;\r
1900                                 }\r
1901                         }\r
1902                         else\r
1903                         {\r
1904                                 ReportWSError("bind", WSAGetLastError());\r
1905                                 do_closesocket(listen_skt);\r
1906                                 listen_skt = INVALID_SOCKET;\r
1907                         }\r
1908 \r
1909                         if(listen_skt == INVALID_SOCKET)\r
1910                                 SetTaskMsg(MSGJPN030);\r
1911                 }\r
1912         }\r
1913         else\r
1914                 ReportWSError("socket create", WSAGetLastError());\r
1915 \r
1916         if(listen_skt != INVALID_SOCKET)\r
1917         {\r
1918 #define  UC(b)  (((int)b)&0xff)\r
1919                 if((command(ctrl_skt,NULL, &CancelFlg, "PORT %d,%d,%d,%d,%d,%d",\r
1920                                 UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]),\r
1921                                 UC(p[0]), UC(p[1])) / 100) != FTP_COMPLETE)\r
1922                 {\r
1923                         SetTaskMsg(MSGJPN031);\r
1924                         do_closesocket(listen_skt);\r
1925                         listen_skt = INVALID_SOCKET;\r
1926                 }\r
1927 //              else\r
1928 //                      DoPrintf("Skt=%u : listener %s port %u",listen_skt,inet_ntoa(saCtrlAddr.sin_addr),ntohs(saCtrlAddr.sin_port));\r
1929         }\r
1930 \r
1931         return(listen_skt);\r
1932 }\r
1933 \r
1934 \r
1935 /*----- ホストへ接続処理中かどうかを返す---------------------------------------\r
1936 *\r
1937 *       Parameter\r
1938 *               なし\r
1939 *\r
1940 *       Return Value\r
1941 *               int ステータス\r
1942 *                       YES/NO\r
1943 *----------------------------------------------------------------------------*/\r
1944 \r
1945 int AskTryingConnect(void)\r
1946 {\r
1947         return(TryConnect);\r
1948 }\r
1949 \r
1950 \r
1951 #if 0\r
1952 ///*----- ブロッキングコールのフックコールバック --------------------------------\r
1953 //*\r
1954 //*     Parameter\r
1955 //*             なし\r
1956 //*\r
1957 //*     Return Value\r
1958 //*             BOOL FALSE\r
1959 //*----------------------------------------------------------------------------*/\r
1960 //\r
1961 //static BOOL CALLBACK BlkHookFnc(void)\r
1962 //{\r
1963 //      BackgrndMessageProc();\r
1964 //\r
1965 //      if(CancelFlg == YES)\r
1966 //      {\r
1967 //              SetTaskMsg(MSGJPN032);\r
1968 //              WSACancelBlockingCall();\r
1969 //              CancelFlg = NO;\r
1970 //      }\r
1971 //      return(FALSE);\r
1972 //}\r
1973 #endif\r
1974 \r
1975 \r
1976 \r
1977 /*----- SOCKS5のコマンドパケットを作成する ------------------------------------\r
1978 *\r
1979 *       Parameter\r
1980 *               SOCKS5REQUEST *Packet : パケットを作成するワーク\r
1981 *               char Cmd : コマンド\r
1982 *               int ValidIP : IPアドレスを使うかどうか(YES/NO)\r
1983 *               ulong IP : IPアドレス\r
1984 *               char *Host : ホスト名\r
1985 *               ushort Port : ポート\r
1986 *\r
1987 *       Return Value\r
1988 *               int コマンドパケットの長さ\r
1989 *----------------------------------------------------------------------------*/\r
1990 \r
1991 static int Socks5MakeCmdPacket(SOCKS5REQUEST *Packet, char Cmd, int ValidIP, ulong IP, char *Host, ushort Port)\r
1992 {\r
1993         uchar *Pos;\r
1994         int Len;\r
1995         int TotalLen;\r
1996 \r
1997         Pos = (uchar *)Packet;\r
1998         Pos += SOCKS5REQUEST_SIZE;\r
1999         TotalLen = SOCKS5REQUEST_SIZE + 2;      /* +2はポートの分 */\r
2000 \r
2001         Packet->Ver = SOCKS5_VER;\r
2002         Packet->Cmd = Cmd;\r
2003         Packet->Rsv = 0;\r
2004         if(ValidIP == YES)\r
2005         {\r
2006                 /* IPアドレスを指定 */\r
2007                 Packet->Type = SOCKS5_ADRS_IPV4;\r
2008                 *((ulong *)Pos) = IP;\r
2009                 Pos += 4;\r
2010                 TotalLen += 4;\r
2011         }\r
2012         else\r
2013         {\r
2014                 /* ホスト名を指定 */\r
2015                 Packet->Type = SOCKS5_ADRS_NAME;\r
2016                 Len = strlen(Host);\r
2017                 *Pos++ = Len;\r
2018                 strcpy(Pos, Host);\r
2019                 Pos += Len;\r
2020                 TotalLen += Len + 1;\r
2021         }\r
2022         *((ushort *)Pos) = Port;\r
2023 \r
2024         return(TotalLen);\r
2025 }\r
2026 \r
2027 \r
2028 /*----- SOCKSのコマンドを送る -------------------------------------------------\r
2029 *\r
2030 *       Parameter\r
2031 *               SOCKET Socket : ソケット\r
2032 *               void *Data : 送るデータ\r
2033 *               int Size : サイズ\r
2034 *\r
2035 *       Return Value\r
2036 *               int ステータス (FFFTP_SUCCESS/FFFTP_FAIL)\r
2037 *----------------------------------------------------------------------------*/\r
2038 \r
2039 static int SocksSendCmd(SOCKET Socket, void *Data, int Size, int *CancelCheckWork)\r
2040 {\r
2041         int Ret;\r
2042 \r
2043         Ret = SendData(Socket, (char *)Data, Size, 0, CancelCheckWork);\r
2044 \r
2045         if(Ret != FFFTP_SUCCESS)\r
2046                 SetTaskMsg(MSGJPN033, *((short *)Data));\r
2047 \r
2048         return(Ret);\r
2049 }\r
2050 \r
2051 \r
2052 /*----- SOCKS5のコマンドに対するリプライパケットを受信する --------------------\r
2053 *\r
2054 *       Parameter\r
2055 *               SOCKET Socket : ソケット\r
2056 *               SOCKS5REPLY *Packet : パケット\r
2057 *\r
2058 *       Return Value\r
2059 *               int ステータス (FFFTP_SUCCESS/FFFTP_FAIL)\r
2060 *----------------------------------------------------------------------------*/\r
2061 \r
2062 static int Socks5GetCmdReply(SOCKET Socket, SOCKS5REPLY *Packet)\r
2063 {\r
2064         uchar *Pos;\r
2065         int Len;\r
2066         int Ret;\r
2067 \r
2068         Pos = (uchar *)Packet;\r
2069         Pos += SOCKS5REPLY_SIZE;\r
2070 \r
2071         if((Ret = ReadNchar(Socket, (char *)Packet, SOCKS5REPLY_SIZE, &CancelFlg)) == FFFTP_SUCCESS)\r
2072         {\r
2073                 if(Packet->Type == SOCKS5_ADRS_IPV4)\r
2074                         Len = 4 + 2;\r
2075                 else if(Packet->Type == SOCKS5_ADRS_IPV6)\r
2076                         Len = 6 + 2;\r
2077                 else\r
2078                 {\r
2079                         if((Ret = ReadNchar(Socket, (char *)Pos, 1, &CancelFlg)) == FFFTP_SUCCESS)\r
2080                         {\r
2081                                 Len = *Pos + 2;\r
2082                                 Pos++;\r
2083                         }\r
2084                 }\r
2085 \r
2086                 if(Ret == FFFTP_SUCCESS)\r
2087                         Ret = ReadNchar(Socket, (char *)Pos, Len, &CancelFlg);\r
2088         }\r
2089 \r
2090         if(Ret != FFFTP_SUCCESS)\r
2091                 SetTaskMsg(MSGJPN034);\r
2092 \r
2093         return(Ret);\r
2094 }\r
2095 \r
2096 \r
2097 /*----- SOCKS4のコマンドに対するリプライパケットを受信する --------------------\r
2098 *\r
2099 *       Parameter\r
2100 *               SOCKET Socket : ソケット\r
2101 *               SOCKS5REPLY *Packet : パケット\r
2102 *\r
2103 *       Return Value\r
2104 *               int ステータス (FFFTP_SUCCESS/FFFTP_FAIL)\r
2105 *----------------------------------------------------------------------------*/\r
2106 \r
2107 static int Socks4GetCmdReply(SOCKET Socket, SOCKS4REPLY *Packet)\r
2108 {\r
2109         int Ret;\r
2110 \r
2111         Ret = ReadNchar(Socket, (char *)Packet, SOCKS4REPLY_SIZE, &CancelFlg);\r
2112 \r
2113         if(Ret != FFFTP_SUCCESS)\r
2114                 DoPrintf(MSGJPN035);\r
2115 \r
2116         return(Ret);\r
2117 }\r
2118 \r
2119 \r
2120 /*----- SOCKS5の認証を行う ----------------------------------------------------\r
2121 *\r
2122 *       Parameter\r
2123 *               SOCKET Socket : ソケット\r
2124 *\r
2125 *       Return Value\r
2126 *               int ステータス (FFFTP_SUCCESS/FFFTP_FAIL)\r
2127 *----------------------------------------------------------------------------*/\r
2128 \r
2129 static int Socks5SelMethod(SOCKET Socket, int *CancelCheckWork)\r
2130 {\r
2131         int Ret;\r
2132         SOCKS5METHODREQUEST Socks5Method;\r
2133         SOCKS5METHODREPLY Socks5MethodReply;\r
2134         SOCKS5USERPASSSTATUS Socks5Status;\r
2135         char Buf[USER_NAME_LEN + PASSWORD_LEN + 4];\r
2136         int Len;\r
2137         int Len2;\r
2138 \r
2139         Ret = FFFTP_SUCCESS;\r
2140         Socks5Method.Ver = SOCKS5_VER;\r
2141         Socks5Method.Num = 1;\r
2142         if(FwallType == FWALL_SOCKS5_NOAUTH)\r
2143                 Socks5Method.Methods[0] = SOCKS5_AUTH_NONE;\r
2144         else\r
2145                 Socks5Method.Methods[0] = SOCKS5_AUTH_USER;\r
2146 \r
2147         if((SocksSendCmd(Socket, &Socks5Method, SOCKS5METHODREQUEST_SIZE, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2148            (ReadNchar(Socket, (char *)&Socks5MethodReply, SOCKS5METHODREPLY_SIZE, &CancelFlg) != FFFTP_SUCCESS) ||\r
2149            (Socks5MethodReply.Method == (uchar)0xFF))\r
2150         {\r
2151                 SetTaskMsg(MSGJPN036);\r
2152                 Ret = FFFTP_FAIL;\r
2153         }\r
2154         else if(Socks5MethodReply.Method == SOCKS5_AUTH_USER)\r
2155         {\r
2156                 DoPrintf("SOCKS5 User/Pass Authentication");\r
2157                 Buf[0] = SOCKS5_USERAUTH_VER;\r
2158                 Len = strlen(FwallUser);\r
2159                 Len2 = strlen(FwallPass);\r
2160                 Buf[1] = Len;\r
2161                 strcpy(Buf+2, FwallUser);\r
2162                 Buf[2 + Len] = Len2;\r
2163                 strcpy(Buf+3+Len, FwallPass);\r
2164 \r
2165                 if((SocksSendCmd(Socket, &Buf, Len+Len2+3, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2166                    (ReadNchar(Socket, (char *)&Socks5Status, SOCKS5USERPASSSTATUS_SIZE, &CancelFlg) != FFFTP_SUCCESS) ||\r
2167                    (Socks5Status.Status != 0))\r
2168                 {\r
2169                         SetTaskMsg(MSGJPN037);\r
2170                         Ret = FFFTP_FAIL;\r
2171                 }\r
2172         }\r
2173         else\r
2174                 DoPrintf("SOCKS5 No Authentication");\r
2175 \r
2176         return(Ret);\r
2177 }\r
2178 \r
2179 \r
2180 /*----- SOCKSのBINDの第2リプライメッセージを受け取る -------------------------\r
2181 *\r
2182 *       Parameter\r
2183 *               SOCKET Socket : ソケット\r
2184 *               SOCKET *Data : データソケットを返すワーク\r
2185 *\r
2186 *       Return Value\r
2187 *               int ステータス (FFFTP_SUCCESS/FFFTP_FAIL)\r
2188 *----------------------------------------------------------------------------*/\r
2189 \r
2190 int SocksGet2ndBindReply(SOCKET Socket, SOCKET *Data)\r
2191 {\r
2192         int Ret;\r
2193         char Buf[300];\r
2194 \r
2195         Ret = FFFTP_FAIL;\r
2196         if((AskHostFireWall() == YES) && (FwallType == FWALL_SOCKS4))\r
2197         {\r
2198                 Socks4GetCmdReply(Socket, (SOCKS4REPLY *)Buf);\r
2199                 *Data = Socket;\r
2200                 Ret = FFFTP_SUCCESS;\r
2201         }\r
2202         else if((AskHostFireWall() == YES) &&\r
2203                         ((FwallType == FWALL_SOCKS5_NOAUTH) || (FwallType == FWALL_SOCKS5_USER)))\r
2204         {\r
2205                 Socks5GetCmdReply(Socket, (SOCKS5REPLY *)Buf);\r
2206                 *Data = Socket;\r
2207                 Ret = FFFTP_SUCCESS;\r
2208         }\r
2209         return(Ret);\r
2210 }\r
2211 \r
2212 \r
2213 \r
2214 // 暗号化通信対応\r
2215 int AskCryptMode(void)\r
2216 {\r
2217         return(CurHost.CryptMode);\r
2218 }\r
2219 \r
2220 int AskUseFTPES(void)\r
2221 {\r
2222         return(CurHost.UseFTPES);\r
2223 }\r
2224 \r
2225 int AskUseFTPIS(void)\r
2226 {\r
2227         return(CurHost.UseFTPIS);\r
2228 }\r
2229 \r
2230 int AskUseSFTP(void)\r
2231 {\r
2232         return(CurHost.UseSFTP);\r
2233 }\r
2234 \r
2235 // 同時接続対応\r
2236 int AskMaxThreadCount(void)\r
2237 {\r
2238         return(CurHost.MaxThreadCount);\r
2239 }\r
2240 \r