--------------------- PatchSet 6219 Date: 2004/06/06 08:38:22 Author: serassio Branch: nt-2_5 Tag: (none) Log: Fixed the running copy detection method, now the Windows process executable name is checked Members: lib/win32lib.c:1.1.32.14->1.1.32.15 Index: squid/lib/win32lib.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/win32lib.c,v retrieving revision 1.1.32.14 retrieving revision 1.1.32.15 diff -u -r1.1.32.14 -r1.1.32.15 --- squid/lib/win32lib.c 3 Jan 2004 14:47:25 -0000 1.1.32.14 +++ squid/lib/win32lib.c 6 Jun 2004 08:38:22 -0000 1.1.32.15 @@ -1,5 +1,5 @@ /* - * $Id: win32lib.c,v 1.1.32.14 2004/01/03 14:47:25 serassio Exp $ + * $Id: win32lib.c,v 1.1.32.15 2004/06/06 08:38:22 serassio Exp $ * * * * * * * * * Legal stuff * * * * * * * * @@ -49,6 +49,9 @@ #include #include #include +#if HAVE_WIN32_PSAPI +#include +#endif THREADLOCAL int ws32_result; THREADLOCAL int _so_err; @@ -134,7 +137,7 @@ return 0; } -int chroot (const char *dirname) +int chroot(const char *dirname) { if (SetCurrentDirectory(dirname)) return 0; @@ -142,9 +145,38 @@ return GetLastError(); } +void GetProcessName(pid_t pid, char * ProcessName) +{ + HANDLE hProcess; + + strcpy(ProcessName, "unknown"); +#if HAVE_WIN32_PSAPI + /* Get a handle to the process. */ + hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | + PROCESS_VM_READ, + FALSE, pid ); + /* Get the process name. */ + if (NULL != hProcess) { + HMODULE hMod; + DWORD cbNeeded; + + if (EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded)) + GetModuleBaseName(hProcess, hMod, ProcessName, sizeof(ProcessName)); + else { + CloseHandle(hProcess); + return; + } + } else + return; + CloseHandle(hProcess); +#endif +} + int kill(pid_t pid, int sig) { HANDLE hProcess; + char MyProcessName[MAX_PATH]; + char ProcessNameToCheck[MAX_PATH]; if (sig == 0) { if ((hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | @@ -153,7 +185,11 @@ return -1; else { CloseHandle(hProcess); - return 0; + GetProcessName(getpid(), MyProcessName); + GetProcessName(pid, ProcessNameToCheck); + if (strcmp(MyProcessName, ProcessNameToCheck) == 0) + return 0; + return -1; } } else return 0;