X-Git-Url: http://git.sourceforge.jp/view?p=ffftp%2Fffftp.git;a=blobdiff_plain;f=main.c;h=60628616768bd4db559e5fd3a71691f36e3475f7;hp=970c3dd9bde520ce1cfde6cb0ca5a2d7b514de77;hb=8ef4e07fd1e721b0181b517444b4dffc859e9c09;hpb=fad6e7c3240d47608cb07f6f2304e1e5091f995a diff --git a/main.c b/main.c index 970c3dd..6062861 100644 --- a/main.c +++ b/main.c @@ -28,6 +28,8 @@ /============================================================================*/ #define STRICT +// IPv6対応 +#include #include #include #include @@ -37,7 +39,8 @@ #include #include #include -#include +// IPv6対応 +//#include #include "common.h" #include "resource.h" @@ -81,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 ); /*===== ローカルなワーク =====*/ @@ -127,6 +132,11 @@ static int SuppressRefresh = 0; static DWORD dwCookie; +// 暗号化通信対応 +static char SSLRootCAFilePath[FMAX_PATH+1]; +// マルチコアCPUの特定環境下でファイル通信中にクラッシュするバグ対策 +static DWORD MainThreadId; + /*===== グローバルなワーク =====*/ @@ -135,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; @@ -210,10 +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; + @@ -300,9 +320,11 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLi InitializeLoadLibraryHook(); #endif + // マルチコアCPUの特定環境下でファイル通信中にクラッシュするバグ対策 #ifdef DISABLE_MULTI_CPUS SetProcessAffinityMask(GetCurrentProcess(), 1); #endif + MainThreadId = GetCurrentThreadId(); // yutaka if(OleInitialize(NULL) != S_OK){ @@ -317,6 +339,9 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLi LoadOpenSSL(); #endif + // SFTP対応 + LoadPuTTY(); + Ret = FALSE; hWndFtp = NULL; hInstFtp = hInstance; @@ -328,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が効くように */ /* コンボボックス内ではアクセラレータを無効にする */ @@ -350,6 +377,8 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLi #ifdef USE_OPENSSL FreeOpenSSL(); #endif + // SFTP対応 + FreePuTTY(); OleUninitialize(); return(Ret); } @@ -382,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(); @@ -392,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"); @@ -463,6 +498,9 @@ 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) @@ -504,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 FFFTP Project (Hiromichi Matsushima, Suguru Kawamoto, IWAMOTO Kouichi, vitamin0x, unarist, raido)."); + 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); @@ -612,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); @@ -825,12 +857,20 @@ 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 : // 同時接続対応 // 中断後に受信バッファに応答が残っていると次のコマンドの応答が正しく処理できない @@ -839,11 +879,21 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA 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) @@ -864,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 : @@ -902,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 : @@ -1148,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; @@ -1156,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; @@ -1220,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 : @@ -1338,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)) @@ -1355,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) { @@ -1375,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; @@ -1446,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; @@ -1466,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; @@ -1478,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; @@ -1950,6 +2045,9 @@ static char *GetToken(char *Str, char *Buf) static void ExitProc(HWND hWnd) { + // 環境依存の不具合対策 + char Tmp[FMAX_PATH+1]; + CancelFlg = YES; CloseTransferThread(); @@ -1978,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); @@ -2051,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."); } @@ -2151,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) { @@ -2182,6 +2297,8 @@ static void ChangeDir(int Win, char *Path) GetRemoteDirForWnd(CACHE_NORMAL, &CancelFlg); } } + // デッドロック対策 + EnableUserOpe(); return; } @@ -2448,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); @@ -2634,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; @@ -2762,7 +2884,11 @@ int BackgrndMessageProc(void) Ret = NO; 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が効くように */ /* コンボボックス内ではアクセラレータを無効にする */ @@ -2884,11 +3010,14 @@ BOOL __stdcall SSLTimeoutCallback(BOOL* pbAborted) BOOL __stdcall SSLConfirmCallback(BOOL* pbAborted, BOOL bVerified, LPCSTR Certificate, LPCSTR CommonName) { BOOL bResult; - int i; 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) { @@ -2919,3 +3048,53 @@ BOOL __stdcall SSLConfirmCallback(BOOL* pbAborted, BOOL bVerified, LPCSTR Certif 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); +} +