OSDN Git Service

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