X-Git-Url: http://git.sourceforge.jp/view?p=ffftp%2Fffftp.git;a=blobdiff_plain;f=main.c;h=60628616768bd4db559e5fd3a71691f36e3475f7;hp=d7e1244ebea43b09164969cd43af4767a8d14359;hb=8ef4e07fd1e721b0181b517444b4dffc859e9c09;hpb=3456a73457a7cc6ddcdd8900f275cd28a9c3b6b7 diff --git a/main.c b/main.c index d7e1244..6062861 100644 --- a/main.c +++ b/main.c @@ -28,6 +28,8 @@ /============================================================================*/ #define STRICT +// IPv6対応 +#include #include #include #include @@ -37,11 +39,14 @@ #include #include #include -#include +// IPv6対応 +//#include #include "common.h" #include "resource.h" #include "aes.h" +// 暗号化通信対応 +#include "sha.h" #include #include "helpid.h" @@ -79,7 +84,9 @@ static void CalcWinSize(void); static void CheckResizeFrame(WPARAM Keys, int x, int y); static void DispDirInfo(void); static void DeleteAlltempFile(void); -static BOOL CALLBACK AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); +// 64ビット対応 +//static BOOL CALLBACK AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); +static INT_PTR CALLBACK AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); static int EnterMasterPasswordAndSet( int Res, HWND hWnd ); /*===== ローカルなワーク =====*/ @@ -125,6 +132,11 @@ static int SuppressRefresh = 0; static DWORD dwCookie; +// 暗号化通信対応 +static char SSLRootCAFilePath[FMAX_PATH+1]; +// マルチコアCPUの特定環境下でファイル通信中にクラッシュするバグ対策 +static DWORD MainThreadId; + /*===== グローバルなワーク =====*/ @@ -133,12 +145,20 @@ HWND hHelpWin = NULL; /* 設定値 */ int WinPosX = CW_USEDEFAULT; int WinPosY = 0; -int WinWidth = 630; -int WinHeight = 393; -int LocalWidth = 309; -int TaskHeight = 50; -int LocalTabWidth[4] = { 120, 90, 60, 37 }; -int RemoteTabWidth[6] = { 120, 90, 60, 37, 60, 60 }; +// 機能が増えたためサイズ変更 +// VGAサイズに収まるようになっていたのをSVGAサイズに引き上げ +//int WinWidth = 630; +//int WinHeight = 393; +//int LocalWidth = 309; +//int TaskHeight = 50; +//int LocalTabWidth[4] = { 120, 90, 60, 37 }; +//int RemoteTabWidth[6] = { 120, 90, 60, 37, 60, 60 }; +int WinWidth = 790; +int WinHeight = 513; +int LocalWidth = 389; +int TaskHeight = 100; +int LocalTabWidth[4] = { 160, 110, 60, 37 }; +int RemoteTabWidth[6] = { 160, 110, 60, 37, 60, 60 }; char UserMailAdrs[USER_MAIL_LEN+1] = { "who@example.com" }; char ViewerName[VIEWERS][FMAX_PATH+1] = { { "notepad" }, { "" }, { "" } }; HFONT ListFont = NULL; @@ -208,8 +228,12 @@ int MirUpDelNotify = YES; int MirDownDelNotify = YES; int FolderAttr = NO; int FolderAttrNum = 777; -// 同時接続対応 -int MaxThreadCount = 1; +// 暗号化通信対応 +BYTE CertificateCacheHash[MAX_CERT_CACHE_HASH][20]; +BYTE SSLRootCAFileHash[20]; +// ファイルアイコン表示対応 +int DispFileIcon = NO; + @@ -232,9 +256,75 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLi int Ret; BOOL Sts; + // プロセス保護 +#ifdef ENABLE_PROCESS_PROTECTION + DWORD ProtectLevel; + char* pCommand; + char Option[FMAX_PATH+1]; + ProtectLevel = PROCESS_PROTECTION_NONE; + pCommand = lpszCmdLine; + while(pCommand = GetToken(pCommand, Option)) + { + if(strcmp(Option, "--protect") == 0) + { + ProtectLevel = PROCESS_PROTECTION_DEFAULT; + break; + } + else if(strcmp(Option, "--protect-high") == 0) + { + ProtectLevel = PROCESS_PROTECTION_HIGH; + break; + } + else if(strcmp(Option, "--protect-medium") == 0) + { + ProtectLevel = PROCESS_PROTECTION_MEDIUM; + break; + } + else if(strcmp(Option, "--protect-low") == 0) + { + ProtectLevel = PROCESS_PROTECTION_LOW; + break; + } + } + if(ProtectLevel != PROCESS_PROTECTION_NONE) + { + SetProcessProtectionLevel(ProtectLevel); + if(!InitializeLoadLibraryHook()) + { + MessageBox(NULL, MSGJPN321, "FFFTP", MB_OK | MB_ICONERROR); + return 0; + } +#ifndef _DEBUG + if(IsDebuggerPresent()) + { + MessageBox(NULL, MSGJPN322, "FFFTP", MB_OK | MB_ICONERROR); + return 0; + } +#endif + if(!UnloadUntrustedModule()) + { + MessageBox(NULL, MSGJPN323, "FFFTP", MB_OK | MB_ICONERROR); + return 0; + } +#ifndef _DEBUG + if(RestartProtectedProcess(" --restart")) + return 0; +#endif + if(!EnableLoadLibraryHook(TRUE)) + { + MessageBox(NULL, MSGJPN324, "FFFTP", MB_OK | MB_ICONERROR); + return 0; + } + } + else + InitializeLoadLibraryHook(); +#endif + + // マルチコアCPUの特定環境下でファイル通信中にクラッシュするバグ対策 #ifdef DISABLE_MULTI_CPUS SetProcessAffinityMask(GetCurrentProcess(), 1); #endif + MainThreadId = GetCurrentThreadId(); // yutaka if(OleInitialize(NULL) != S_OK){ @@ -244,10 +334,14 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLi InitCommonControls(); + // FTPS対応 #ifdef USE_OPENSSL LoadOpenSSL(); #endif + // SFTP対応 + LoadPuTTY(); + Ret = FALSE; hWndFtp = NULL; hInstFtp = hInstance; @@ -259,7 +353,9 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLi if((Sts == 0) || (Sts == -1)) break; - if(!HtmlHelp(NULL, NULL, HH_PRETRANSLATEMESSAGE, (DWORD)&Msg)) + // 64ビット対応 +// if(!HtmlHelp(NULL, NULL, HH_PRETRANSLATEMESSAGE, (DWORD)&Msg)) + if(!HtmlHelp(NULL, NULL, HH_PRETRANSLATEMESSAGE, (DWORD_PTR)&Msg)) { /* ディレクトリ名の表示コンボボックスでBSやRETが効くように */ /* コンボボックス内ではアクセラレータを無効にする */ @@ -277,9 +373,12 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLi Ret = Msg.wParam; } UnregisterClass(FtpClassStr, hInstFtp); + // FTPS対応 #ifdef USE_OPENSSL FreeOpenSSL(); #endif + // SFTP対応 + FreePuTTY(); OleUninitialize(); return(Ret); } @@ -312,7 +411,9 @@ static int InitApp(LPSTR lpszCmdLine, int cmdShow) aes_init(); srand(GetTickCount()); - HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD)&dwCookie); + // 64ビット対応 +// HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD)&dwCookie); + HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD_PTR)&dwCookie); SaveUpdateBellInfo(); @@ -322,7 +423,11 @@ static int InitApp(LPSTR lpszCmdLine, int cmdShow) { Accel = LoadAccelerators(hInstFtp, MAKEINTRESOURCE(ffftp_accel)); - GetTempPath(FMAX_PATH, TmpPath); + // 環境依存の不具合対策 +// GetTempPath(FMAX_PATH, TmpPath); + GetAppTempPath(TmpPath); + _mkdir(TmpPath); + SetYenTail(TmpPath); GetModuleFileName(NULL, HelpPath, FMAX_PATH); strcpy(GetFileName(HelpPath), "ffftp.chm"); @@ -392,6 +497,10 @@ static int InitApp(LPSTR lpszCmdLine, int cmdShow) // 暗号化通信対応 SetSSLTimeoutCallback(TimeOut * 1000, SSLTimeoutCallback); + SetSSLConfirmCallback(SSLConfirmCallback); + GetModuleFileName(NULL, SSLRootCAFilePath, FMAX_PATH); + strcpy(GetFileName(SSLRootCAFilePath), "ssl.pem"); + LoadSSLRootCAFile(); LoadJre(); if(NoRasControl == NO) @@ -433,7 +542,7 @@ static int InitApp(LPSTR lpszCmdLine, int cmdShow) DispWindowTitle(); // SourceForge.JPによるフォーク // SetTaskMsg("FFFTP Ver." VER_STR " Copyright(C) 1997-2010 Sota & cooperators."); - SetTaskMsg("FFFTP Ver." VER_STR " Copyright(C) 1997-2010 Sota & cooperators.\r\nCopyright (C) 2011 Hiromichi Matsushima, Suguru Kawamoto."); + SetTaskMsg("FFFTP Ver." VER_STR " Copyright(C) 1997-2010 Sota & cooperators.\r\nCopyright (C) 2011-2012 FFFTP Project (Hiromichi Matsushima, Suguru Kawamoto, IWAMOTO Kouichi, vitamin0x, unarist, Asami, fortran90, tomo1192, Yuji Tanaka, Moriguchi Hirokazu)."); if(ForceIni) SetTaskMsg("%s%s", MSGJPN283, IniPath); @@ -541,13 +650,7 @@ static int MakeAllWindows(int cmdShow) WinPosX = CW_USEDEFAULT; WinPosY = 0; } - // UTF-8対応 - // ユーザー定義のクラスはデフォルトのWNDPROCがShift_JIS専用のため -// hWndFtp = CreateWindow(FtpClassStr, "FFFTP", -// WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, -// WinPosX, WinPosY, WinWidth, WinHeight, -// HWND_DESKTOP, 0, hInstFtp, NULL); - hWndFtp = CreateWindowA(FtpClassStr, "FFFTP", + hWndFtp = CreateWindow(FtpClassStr, "FFFTP", WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, WinPosX, WinPosY, WinWidth, WinHeight, HWND_DESKTOP, 0, hInstFtp, NULL); @@ -754,21 +857,43 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA { PAINTSTRUCT ps; LPTOOLTIPTEXT lpttt; + // UTF-8対応 + LPTOOLTIPTEXTW wlpttt; RECT Rect; int TmpTransType; switch (message) { + // 自動切断対策 + case WM_TIMER : + if(wParam == 1) + NoopProc(); + break; + case WM_COMMAND : + // 同時接続対応 + // 中断後に受信バッファに応答が残っていると次のコマンドの応答が正しく処理できない + if(CancelFlg == YES) + RemoveReceivedData(AskCmdCtrlSkt()); switch(LOWORD(wParam)) { case MENU_CONNECT : + // 自動切断対策 + KillTimer(hWnd, 1); ConnectProc(DLG_TYPE_CON, -1); + // 自動切断対策 + if(AskNoopInterval() > 0) + SetTimer(hWnd, 1, AskNoopInterval() * 1000, NULL); break; case MENU_CONNECT_NUM : + // 自動切断対策 + KillTimer(hWnd, 1); ConnectProc(DLG_TYPE_CON, (int)lParam); + // 自動切断対策 + if(AskNoopInterval() > 0) + SetTimer(hWnd, 1, AskNoopInterval() * 1000, NULL); if(AskConnecting() == YES) { if(HIWORD(wParam) & OPT_MIRROR) @@ -789,11 +914,21 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA break; case MENU_SET_CONNECT : + // 自動切断対策 + KillTimer(hWnd, 1); ConnectProc(DLG_TYPE_SET, -1); + // 自動切断対策 + if(AskNoopInterval() > 0) + SetTimer(hWnd, 1, AskNoopInterval() * 1000, NULL); break; case MENU_QUICK : + // 自動切断対策 + KillTimer(hWnd, 1); QuickConnectProc(); + // 自動切断対策 + if(AskNoopInterval() > 0) + SetTimer(hWnd, 1, AskNoopInterval() * 1000, NULL); break; case MENU_DISCONNECT : @@ -827,7 +962,12 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA case MENU_HIST_18 : case MENU_HIST_19 : case MENU_HIST_20 : + // 自動切断対策 + KillTimer(hWnd, 1); HistoryConnectProc(LOWORD(wParam)); + // 自動切断対策 + if(AskNoopInterval() > 0) + SetTimer(hWnd, 1, AskNoopInterval() * 1000, NULL); break; case MENU_UPDIR : @@ -1010,12 +1150,16 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA break; case MENU_FILTER : + // 同時接続対応 + CancelFlg = NO; SetFilter(&CancelFlg); break; case MENU_SORT : if(SortSetting() == YES) { + // 同時接続対応 + CancelFlg = NO; LocalFileSort = AskSortType(ITEM_LFILE); LocalDirSort = AskSortType(ITEM_LDIR); RemoteFileSort = AskSortType(ITEM_RFILE); @@ -1069,6 +1213,7 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA case MENU_KNJ_EUC : case MENU_KNJ_JIS : case MENU_KNJ_UTF8N : + case MENU_KNJ_UTF8BOM : case MENU_KNJ_NONE : SetHostKanjiCode(LOWORD(wParam)); break; @@ -1077,6 +1222,7 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA case MENU_L_KNJ_EUC : case MENU_L_KNJ_JIS : case MENU_L_KNJ_UTF8N : + case MENU_L_KNJ_UTF8BOM : SetLocalKanjiCode(LOWORD(wParam)); break; @@ -1085,6 +1231,8 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA break; case MENU_REFRESH : + // 同時接続対応 + CancelFlg = NO; SuppressRefresh = 1; GetLocalDirForWnd(); if(CheckClosedAndReconnect() == FFFTP_SUCCESS) @@ -1109,6 +1257,8 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA break; case REFRESH_REMOTE : + // 同時接続対応 + CancelFlg = NO; SuppressRefresh = 1; if(CheckClosedAndReconnect() == FFFTP_SUCCESS) GetRemoteDirForWnd(CACHE_REFRESH, &CancelFlg); @@ -1137,7 +1287,9 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA break; case MENU_HELP_TROUBLE : - ShellExecute(NULL, "open", MYWEB_URL, NULL, ".", SW_SHOW); + // 任意のコードが実行されるバグ修正 +// ShellExecute(NULL, "open", MYWEB_URL, NULL, ".", SW_SHOW); + ShellExecute(NULL, "open", MYWEB_URL, NULL, NULL, SW_SHOW); break; case MENU_BMARK_ADD : @@ -1173,6 +1325,8 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA break; case MENU_DOTFILE : + // 同時接続対応 + CancelFlg = NO; DotFile ^= 1; DispDotFileMode(); GetLocalDirForWnd(); @@ -1253,6 +1407,12 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA LocalRbuttonMenu(1); break; +#if defined(HAVE_TANDEM) + case MENU_SWITCH_OSS : + SwitchOSSProc(); + break; +#endif + default : if((LOWORD(wParam) >= MENU_BMARK_TOP) && (LOWORD(wParam) < MENU_BMARK_TOP+100)) @@ -1270,8 +1430,13 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA switch(((LPNMHDR)lParam)->code) { /* ツールチップコントロールメッセージの処理 */ - case TTN_NEEDTEXT: + // UTF-8対応 +// case TTN_NEEDTEXT: + case TTN_NEEDTEXTW: lpttt = (LPTOOLTIPTEXT)lParam; + // UTF-8対応 + // lptttは単なる警告回避用 + wlpttt = (LPTOOLTIPTEXTW)lParam; lpttt->hinst = hInstFtp; switch(lpttt->hdr.idFrom) { @@ -1290,7 +1455,15 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA case MENU_DOWNLOAD : lpttt->lpszText = MSGJPN157; break; +#if defined(HAVE_TANDEM) + case MENU_DOWNLOAD_AS : + lpttt->lpszText = MSGJPN065; + break; + case MENU_UPLOAD_AS : + lpttt->lpszText = MSGJPN064; + break; +#endif case MENU_UPLOAD : lpttt->lpszText = MSGJPN158; break; @@ -1361,6 +1534,10 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA lpttt->lpszText = MSGJPN308; break; + case MENU_KNJ_UTF8BOM : + lpttt->lpszText = MSGJPN330; + break; + case MENU_KNJ_NONE : lpttt->lpszText = MSGJPN173; break; @@ -1381,6 +1558,10 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA lpttt->lpszText = MSGJPN312; break; + case MENU_L_KNJ_UTF8BOM : + lpttt->lpszText = MSGJPN331; + break; + case MENU_KANACNV : lpttt->lpszText = MSGJPN174; break; @@ -1393,15 +1574,14 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA lpttt->lpszText = MSGJPN176; break; } - // UTF-8からShift_JISへ変換 + // UTF-8対応 + // UTF-8からUTF-16 LEへ変換 { static wchar_t StringBufferUTF16[1024]; - static char StringBufferSJIS[1024]; if(lpttt->lpszText) { MtoW(StringBufferUTF16, sizeof(StringBufferUTF16)/ sizeof(wchar_t), lpttt->lpszText, -1); - WtoA(StringBufferSJIS, sizeof(StringBufferSJIS)/ sizeof(char), StringBufferUTF16, -1); - lpttt->lpszText = StringBufferSJIS; + wlpttt->lpszText = StringBufferUTF16; } } break; @@ -1409,6 +1589,8 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA case LVN_COLUMNCLICK : if(((NMHDR *)lParam)->hwndFrom == GetLocalHwnd()) { + // 同時接続対応 + CancelFlg = NO; SetSortTypeByColumn(WIN_LOCAL, ((NM_LISTVIEW *)lParam)->iSubItem); ReSortDispList(WIN_LOCAL, &CancelFlg); } @@ -1416,6 +1598,8 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA { if(((NM_LISTVIEW *)lParam)->iSubItem != 4) { + // 同時接続対応 + CancelFlg = NO; SetSortTypeByColumn(WIN_REMOTE, ((NM_LISTVIEW *)lParam)->iSubItem); ReSortDispList(WIN_REMOTE, &CancelFlg); } @@ -1697,6 +1881,24 @@ static int AnalyzeComLine(char *Str, int *AutoConnect, int *CmdOption, char *unc { hHelpWin = HtmlHelp(NULL, AskHelpFilePath(), HH_HELP_CONTEXT, IDH_HELP_TOPIC_0000024); } + // プロセス保護 +#ifdef ENABLE_PROCESS_PROTECTION + else if(strcmp(Tmp, "--restart") == 0) + { + } + else if(strcmp(Tmp, "--protect") == 0) + { + } + else if(strcmp(Tmp, "--protect-high") == 0) + { + } + else if(strcmp(Tmp, "--protect-medium") == 0) + { + } + else if(strcmp(Tmp, "--protect-low") == 0) + { + } +#endif else { SetTaskMsg(MSGJPN180, Tmp); @@ -1843,6 +2045,9 @@ static char *GetToken(char *Str, char *Buf) static void ExitProc(HWND hWnd) { + // 環境依存の不具合対策 + char Tmp[FMAX_PATH+1]; + CancelFlg = YES; CloseTransferThread(); @@ -1871,6 +2076,14 @@ static void ExitProc(HWND hWnd) else DeleteCache(); + // 環境依存の不具合対策 + GetAppTempPath(Tmp); + SetYenTail(Tmp); + strcat(Tmp, "file"); + _rmdir(Tmp); + GetAppTempPath(Tmp); + _rmdir(Tmp); + if(RasClose == YES) { DisconnectRas(RasCloseNotify); @@ -1944,6 +2157,10 @@ void DoubleClickProc(int Win, int Mode, int App) strcpy(Remote, TmpPath); SetYenTail(Remote); + // 環境依存の不具合対策 + strcat(Remote, "file"); + _mkdir(Remote); + SetYenTail(Remote); if (UseDiffViewer == YES) { strcat(Remote, "remote."); } @@ -1990,6 +2207,8 @@ void DoubleClickProc(int Win, int Mode, int App) // if((Sts = DoDownLoad(AskCmdCtrlSkt(), &MainTransPkt, NO)) == 429) // { // ReConnectCmdSkt(); + // 同時接続対応 + CancelFlg = NO; Sts = DoDownLoad(AskCmdCtrlSkt(), &MainTransPkt, NO, &CancelFlg); // } } @@ -2042,6 +2261,11 @@ static void ChangeDir(int Win, char *Path) char Local[FMAX_PATH+1]; char Remote[FMAX_PATH+1]; + // 同時接続対応 + CancelFlg = NO; + + // デッドロック対策 + DisableUserOpe(); Sync = AskSyncMoveMode(); if(Sync == YES) { @@ -2073,6 +2297,8 @@ static void ChangeDir(int Win, char *Path) GetRemoteDirForWnd(CACHE_NORMAL, &CancelFlg); } } + // デッドロック対策 + EnableUserOpe(); return; } @@ -2330,6 +2556,8 @@ void ExecViewer(char *Fname, int App) char AssocProg[FMAX_PATH+1]; char ComLine[FMAX_PATH*2+3+1]; char CurDir[FMAX_PATH+1]; + // 任意のコードが実行されるバグ修正 + char SysDir[FMAX_PATH+1]; /* FindExecutable()は関連付けられたプログラムのパス名にスペースが */ /* 含まれている時、間違ったパス名を返す事がある。 */ @@ -2337,7 +2565,10 @@ void ExecViewer(char *Fname, int App) AskLocalCurDir(CurDir, FMAX_PATH); - if((App == -1) && (FindExecutable(Fname, NULL, AssocProg) > (HINSTANCE)32)) + // 任意のコードが実行されるバグ修正 + // 拡張子が無いと補完されるため +// if((App == -1) && (FindExecutable(Fname, NULL, AssocProg) > (HINSTANCE)32)) + if((App == -1) && (strlen(GetFileExt(GetFileName(Fname))) > 0) && (FindExecutable(Fname, NULL, AssocProg) > (HINSTANCE)32)) { DoPrintf("ShellExecute - %s", Fname); ShellExecute(NULL, "open", Fname, NULL, CurDir, SW_SHOW); @@ -2357,10 +2588,26 @@ void ExecViewer(char *Fname, int App) memset(&Startup, NUL, sizeof(STARTUPINFO)); Startup.cb = sizeof(STARTUPINFO); Startup.wShowWindow = SW_SHOW; - if(CreateProcess(NULL, ComLine, NULL, NULL, FALSE, 0, NULL, NULL, &Startup, &Info) == FALSE) + // 任意のコードが実行されるバグ修正 +// if(CreateProcess(NULL, ComLine, NULL, NULL, FALSE, 0, NULL, NULL, &Startup, &Info) == FALSE) +// { +// SetTaskMsg(MSGJPN182, GetLastError()); +// SetTaskMsg(">>%s", ComLine); +// } + if(GetCurrentDirectory(FMAX_PATH, CurDir) > 0) { - SetTaskMsg(MSGJPN182, GetLastError()); - SetTaskMsg(">>%s", ComLine); + if(GetSystemDirectory(SysDir, FMAX_PATH) > 0) + { + if(SetCurrentDirectory(SysDir)) + { + if(CreateProcess(NULL, ComLine, NULL, NULL, FALSE, 0, NULL, NULL, &Startup, &Info) == FALSE) + { + SetTaskMsg(MSGJPN182, GetLastError()); + SetTaskMsg(">>%s", ComLine); + } + SetCurrentDirectory(CurDir); + } + } } } return; @@ -2385,6 +2632,8 @@ void ExecViewer2(char *Fname1, char *Fname2, int App) char AssocProg[FMAX_PATH+1]; char ComLine[FMAX_PATH*2+3+1]; char CurDir[FMAX_PATH+1]; + // 任意のコードが実行されるバグ修正 + char SysDir[FMAX_PATH+1]; /* FindExecutable()は関連付けられたプログラムのパス名にスペースが */ /* 含まれている時、間違ったパス名を返す事がある。 */ @@ -2404,10 +2653,26 @@ void ExecViewer2(char *Fname1, char *Fname2, int App) memset(&Startup, NUL, sizeof(STARTUPINFO)); Startup.cb = sizeof(STARTUPINFO); Startup.wShowWindow = SW_SHOW; - if(CreateProcess(NULL, ComLine, NULL, NULL, FALSE, 0, NULL, NULL, &Startup, &Info) == FALSE) + // 任意のコードが実行されるバグ修正 +// if(CreateProcess(NULL, ComLine, NULL, NULL, FALSE, 0, NULL, NULL, &Startup, &Info) == FALSE) +// { +// SetTaskMsg(MSGJPN182, GetLastError()); +// SetTaskMsg(">>%s", ComLine); +// } + if(GetCurrentDirectory(FMAX_PATH, CurDir) > 0) { - SetTaskMsg(MSGJPN182, GetLastError()); - SetTaskMsg(">>%s", ComLine); + if(GetSystemDirectory(SysDir, FMAX_PATH) > 0) + { + if(SetCurrentDirectory(SysDir)) + { + if(CreateProcess(NULL, ComLine, NULL, NULL, FALSE, 0, NULL, NULL, &Startup, &Info) == FALSE) + { + SetTaskMsg(MSGJPN182, GetLastError()); + SetTaskMsg(">>%s", ComLine); + } + SetCurrentDirectory(CurDir); + } + } } return; @@ -2489,7 +2754,9 @@ static void DeleteAlltempFile(void) * BOOL TRUE/FALSE *----------------------------------------------------------------------------*/ -static BOOL CALLBACK AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +// 64ビット対応 +//static BOOL CALLBACK AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +static INT_PTR CALLBACK AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static char Tmp[80]; int Ver; @@ -2615,10 +2882,13 @@ int BackgrndMessageProc(void) int Ret; Ret = NO; - SendMessage(GetMainHwnd(), WM_NULL, 0, 0); while(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) { - if(!HtmlHelp(NULL, NULL, HH_PRETRANSLATEMESSAGE, (DWORD)&Msg)) + // マルチコアCPUの特定環境下でファイル通信中にクラッシュするバグ対策 +// if(!HtmlHelp(NULL, NULL, HH_PRETRANSLATEMESSAGE, (DWORD)&Msg)) + // 64ビット対応 +// if(!IsMainThread() || !HtmlHelp(NULL, NULL, HH_PRETRANSLATEMESSAGE, (DWORD)&Msg)) + if(!IsMainThread() || !HtmlHelp(NULL, NULL, HH_PRETRANSLATEMESSAGE, (DWORD_PTR)&Msg)) { /* ディレクトリ名の表示コンボボックスでBSやRETが効くように */ /* コンボボックス内ではアクセラレータを無効にする */ @@ -2684,12 +2954,29 @@ int AskAutoExit(void) int EnterMasterPasswordAndSet( int Res, HWND hWnd ) { char buf[MAX_PASSWORD_LEN + 1]; + // パスワードの入力欄を非表示 + // 非表示にしたため新しいパスワードを2回入力させる + char buf1[MAX_PASSWORD_LEN + 1]; char *p; int Flag; buf[0] = NUL; if( InputDialogBox(Res, hWnd, NULL, buf, MAX_PASSWORD_LEN + 1, &Flag, IDH_HELP_TOPIC_0000064) == YES){ + // パスワードの入力欄を非表示 + if(Res == newmasterpasswd_dlg) + { + buf1[0] = NUL; + if( InputDialogBox(Res, hWnd, NULL, buf1, MAX_PASSWORD_LEN + 1, + &Flag, IDH_HELP_TOPIC_0000064) != YES){ + return 0; + } + if(strcmp(buf, buf1) != 0) + { + MessageBox(hWnd, MSGJPN325, "FFFTP", MB_OK | MB_ICONERROR); + return 0; + } + } /* 末尾の空白を削除 */ RemoveTailingSpaces(buf); /* 先頭の空白を削除 */ @@ -2710,17 +2997,104 @@ int EnterMasterPasswordAndSet( int Res, HWND hWnd ) } // 暗号化通信対応 -BOOL __stdcall SSLTimeoutCallback() +BOOL __stdcall SSLTimeoutCallback(BOOL* pbAborted) { Sleep(1); if(BackgrndMessageProc() == YES) return TRUE; - // 念のためツールバーのMENU_ABORTも確認 -// if(MainTransPkt.Abort != ABORT_NONE) -// { -// MainTransPkt.Abort = ABORT_NONE; -// return TRUE; -// } + if(*pbAborted == YES) + return TRUE; return FALSE; } +BOOL __stdcall SSLConfirmCallback(BOOL* pbAborted, BOOL bVerified, LPCSTR Certificate, LPCSTR CommonName) +{ + BOOL bResult; + uint32 Hash[5]; + int i; + char* pm0; + bResult = FALSE; + sha_memory((char*)Certificate, (uint32)(strlen(Certificate) * sizeof(char)), (uint32*)&Hash); + // sha.cはビッグエンディアンのため + for(i = 0; i < 5; i++) + Hash[i] = _byteswap_ulong(Hash[i]); + i = 0; + while(i < MAX_CERT_CACHE_HASH) + { + if(memcmp(&CertificateCacheHash[i], &Hash, 20) == 0) + { + bResult = TRUE; + break; + } + i++; + } + if(!bResult) + { + if(pm0 = AllocateStringM(strlen(Certificate) + 1024)) + { + sprintf(pm0, MSGJPN326, IsHostNameMatched(AskHostAdrs(), CommonName) ? MSGJPN327 : MSGJPN328, bVerified ? MSGJPN327 : MSGJPN328, Certificate); + if(MessageBox(GetMainHwnd(), pm0, "FFFTP", MB_YESNO) == IDYES) + { + for(i = MAX_CERT_CACHE_HASH - 1; i >= 1; i--) + memcpy(&CertificateCacheHash[i], &CertificateCacheHash[i - 1], 20); + memcpy(&CertificateCacheHash[0], &Hash, 20); + bResult = TRUE; + } + FreeDuplicatedString(pm0); + } + } + if(!bResult) + *pbAborted = YES; + return bResult; +} + +BOOL LoadSSLRootCAFile() +{ + BOOL bResult; + HANDLE hFile; + DWORD Size; + BYTE* pBuffer; + uint32 Hash[5]; + int i; + bResult = FALSE; + if((hFile = CreateFile(SSLRootCAFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE) + { + Size = GetFileSize(hFile, NULL); + if(pBuffer = (BYTE*)malloc(Size)) + { + if(ReadFile(hFile, pBuffer, Size, &Size, NULL)) + { + sha_memory((char*)pBuffer, (uint32)Size, (uint32*)&Hash); + // sha.cはビッグエンディアンのため + for(i = 0; i < 5; i++) + Hash[i] = _byteswap_ulong(Hash[i]); + // 同梱する"ssl.pem"に合わせてSHA1ハッシュ値を変更すること + if(memcmp(&Hash, &SSLRootCAFileHash, 20) == 0 || memcmp(&Hash, "\xF0\x1B\x48\x26\x67\x44\x3A\xFF\x0A\x16\xD3\xBB\x8A\x33\xEB\x70\x6D\x75\xA6\x0D", 20) == 0 + || DialogBox(GetFtpInst(), MAKEINTRESOURCE(updatesslroot_dlg), GetMainHwnd(), ExeEscDialogProc) == YES) + { + memcpy(&SSLRootCAFileHash, &Hash, 20); + if(SetSSLRootCertificate(pBuffer, Size)) + bResult = TRUE; + } + } + free(pBuffer); + } + CloseHandle(hFile); + } + return bResult; +} + +// マルチコアCPUの特定環境下でファイル通信中にクラッシュするバグ対策 +BOOL IsMainThread() +{ + if(GetCurrentThreadId() != MainThreadId) + return FALSE; + return TRUE; +} + +// ファイルアイコン表示対応 +int AskDispFileIcon(void) +{ + return(DispFileIcon); +} +