X-Git-Url: http://git.sourceforge.jp/view?p=ffftp%2Fffftp.git;a=blobdiff_plain;f=main.c;h=79d370907448275787251a581a061ac5a69b5bdc;hp=704be471f728049b6caa0a8d1f1f8d377a99f6ac;hb=e9287654de8df4b44ca76c58fdee7056c9499b68;hpb=dce74878dd044e66c99341f617cb1b9de781acad diff --git a/main.c b/main.c index 704be47..79d3709 100644 --- a/main.c +++ b/main.c @@ -42,6 +42,8 @@ #include "common.h" #include "resource.h" #include "aes.h" +// 暗号化通信対応 +#include "sha.h" #include #include "helpid.h" @@ -133,12 +135,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 +218,8 @@ int MirUpDelNotify = YES; int MirDownDelNotify = YES; int FolderAttr = NO; int FolderAttrNum = 777; -// 同時接続対応 -int MaxThreadCount = 1; +// 暗号化通信対応 +BYTE CertificateCacheHash[MAX_CERT_CACHE_HASH][20]; @@ -232,6 +242,70 @@ 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 + #ifdef DISABLE_MULTI_CPUS SetProcessAffinityMask(GetCurrentProcess(), 1); #endif @@ -244,6 +318,7 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLi InitCommonControls(); + // FTPS対応 #ifdef USE_OPENSSL LoadOpenSSL(); #endif @@ -277,6 +352,7 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLi Ret = Msg.wParam; } UnregisterClass(FtpClassStr, hInstFtp); + // FTPS対応 #ifdef USE_OPENSSL FreeOpenSSL(); #endif @@ -392,6 +468,7 @@ static int InitApp(LPSTR lpszCmdLine, int cmdShow) // 暗号化通信対応 SetSSLTimeoutCallback(TimeOut * 1000, SSLTimeoutCallback); + SetSSLConfirmCallback(SSLConfirmCallback); LoadJre(); if(NoRasControl == NO) @@ -433,7 +510,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 FFFTP Project (Hiromichi Matsushima, Suguru Kawamoto, IWAMOTO Kouichi, vitamin0x, unarist, Asami, fortran90, tomo1192)."); if(ForceIni) SetTaskMsg("%s%s", MSGJPN283, IniPath); @@ -761,6 +838,10 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA switch (message) { case WM_COMMAND : + // 同時接続対応 + // 中断後に受信バッファに応答が残っていると次のコマンドの応答が正しく処理できない + if(CancelFlg == YES) + RemoveReceivedData(AskCmdCtrlSkt()); switch(LOWORD(wParam)) { case MENU_CONNECT : @@ -1010,12 +1091,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 +1154,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 +1163,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 +1172,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 +1198,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 +1228,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 +1266,8 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA break; case MENU_DOTFILE : + // 同時接続対応 + CancelFlg = NO; DotFile ^= 1; DispDotFileMode(); GetLocalDirForWnd(); @@ -1361,6 +1456,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 +1480,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; @@ -1409,6 +1512,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 +1521,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 +1804,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); @@ -1990,6 +2115,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 +2169,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 +2205,8 @@ static void ChangeDir(int Win, char *Path) GetRemoteDirForWnd(CACHE_NORMAL, &CancelFlg); } } + // デッドロック対策 + EnableUserOpe(); return; } @@ -2330,6 +2464,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 +2473,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) && strrchr(Fname, '.') > strrchr(Fname, '\\') && (FindExecutable(Fname, NULL, AssocProg) > (HINSTANCE)32)) { DoPrintf("ShellExecute - %s", Fname); ShellExecute(NULL, "open", Fname, NULL, CurDir, SW_SHOW); @@ -2357,10 +2496,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 +2540,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 +2561,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; @@ -2683,12 +2856,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); /* 先頭の空白を削除 */ @@ -2709,17 +2899,51 @@ 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; + int i; + uint32 Hash[5]; + char* pm0; + bResult = FALSE; + sha_memory((char*)Certificate, (uint32)(strlen(Certificate) * sizeof(char)), (uint32*)&Hash); + 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; +} +