Revision: 10697 https://osdn.net/projects/ttssh2/scm/svn/commits/10697 Author: nmaya Date: 2023-05-07 23:57:28 +0900 (Sun, 07 May 2023) Log Message: ----------- 元にした PuTTY の該当箇所の追記・関数名の修正など ticket #45653 Ticket Links: ------------ https://osdn.net/projects/ttssh2/tracker/detail/45653 Modified Paths: -------------- trunk/ttssh2/libsshagentc/sshagentc/agentc.cpp -------------- next part -------------- Modified: trunk/ttssh2/libsshagentc/sshagentc/agentc.cpp =================================================================== --- trunk/ttssh2/libsshagentc/sshagentc/agentc.cpp 2023-05-02 14:00:28 UTC (rev 10696) +++ trunk/ttssh2/libsshagentc/sshagentc/agentc.cpp 2023-05-07 14:57:28 UTC (rev 10697) @@ -149,7 +149,7 @@ /** * pagent named pipe\x96\xBC - * from putty windows/utils/agent_named_pipe_name.c + * from PuTTY windows/utils/agent_named_pipe_name.c */ static char *agent_named_pipe_name(void) { @@ -328,7 +328,7 @@ /** * sid\x82̎擾 - * PuTTY security.c get_user_sid() + * from PuTTY windows/utils/security.c get_user_sid() */ #if PUTTY_SHM static PSID get_user_sid(void) @@ -386,7 +386,7 @@ /** * SECURITY_ATTRIBUTES \x82̎擾 - * PuTTY windows/agent-client.c wm_copydata_agent_query() \x82\xF0\x8EQ\x8Dl\x82ɂ\xB5\x82\xBD + * from PuTTY windows/agent-client.c wm_copydata_agent_query() \x82̈ꕔ\x82\xF0\x90\xE8\x8Fo\x82\xB5 * * @param psa SECURITY_ATTRIBUTES \x82ւ̃|\x83C\x83\x93\x83^ * \x82\xB1\x82\xB1\x82Ɏ擾\x82\xB7\x82\xE9 @@ -421,17 +421,18 @@ } #endif +#if PUTTY_SHM /** * agent(pageant)\x82ƒʐM,\x8B\xA4\x97L\x83\x81\x83\x82\x83\x8A\x8Co\x97R + * PuTTY windows/agent-client.c wm_copydata_agent_query() \x82Ɠ\xAF\x93\x99 * * @retval FALSE \x83G\x83\x89\x81[ */ -#if PUTTY_SHM -static BOOL query_SHM(const Buffer &request, Buffer &reply) +static BOOL query_wm_copydata(const Buffer &request, Buffer &reply) { HWND hwnd; char mapname[25]; - HANDLE fmap = NULL; + HANDLE filemap = NULL; unsigned char *p = NULL; unsigned long len; BOOL ret = FALSE; @@ -452,18 +453,18 @@ SECURITY_ATTRIBUTES sa; psa = get_sa(&sa); sprintf_s(mapname, "PageantRequest%08x", (unsigned)GetCurrentThreadId()); - fmap = CreateFileMappingA(INVALID_HANDLE_VALUE, psa, PAGE_READWRITE, - 0, AGENT_MAX_MSGLEN, mapname); - if (!fmap) { + filemap = CreateFileMappingA(INVALID_HANDLE_VALUE, psa, PAGE_READWRITE, + 0, AGENT_MAX_MSGLEN, mapname); + if (!filemap) { goto agent_error; } - if ((p = (unsigned char *)MapViewOfFile(fmap, FILE_MAP_WRITE, 0, 0, 0)) == NULL) { + if ((p = (unsigned char *)MapViewOfFile(filemap, FILE_MAP_WRITE, 0, 0, 0)) == NULL) { goto agent_error; } COPYDATASTRUCT cds; -#define AGENT_COPYDATA_ID 0x804e50ba // ? +#define AGENT_COPYDATA_ID 0x804e50ba // from putty windows\platform.h cds.dwData = AGENT_COPYDATA_ID; cds.cbData = (DWORD)(strlen(mapname) + 1); cds.lpData = mapname; @@ -480,8 +481,8 @@ if (p) { UnmapViewOfFile(p); } - if (fmap) { - CloseHandle(fmap); + if (filemap) { + CloseHandle(filemap); } if (ret == 0) { reply.append_uint32(5); @@ -495,6 +496,9 @@ } #endif +/** + * PuTTY windows/agent-client.c agent_query() \x82Ɠ\xAF\x93\x99 + */ static BOOL query(const Buffer &request, Buffer &reply) { BOOL r; @@ -511,7 +515,7 @@ } #endif #if PUTTY_SHM - r = query_SHM(request, reply); + r = query_wm_copydata(request, reply); if (r) { goto finish; } @@ -622,6 +626,9 @@ return "libsshagent 0.1"; } +/** + * PuTTY aqsync.c agent_query_synchronous() \x82Ɠ\xAF\x93\x99 + */ void putty_agent_query_synchronous(const void *req_ptr, int req_len, void **rep_ptr, int *rep_len) { Buffer request; @@ -634,6 +641,9 @@ } #if PUTTY_NAMEDPIPE +/** + * PuTTY windows/agent-client.c named_pipe_agent_exists() \x82Ɠ\xAF\x93\x99 + */ static BOOL check_puttyagent_namedpipe() { char *pname = agent_named_pipe_name(); @@ -643,6 +653,21 @@ } #endif +#if PUTTY_SHM +/** + * from PuTTY windows\agent-client.c wm_copydata_agent_exists() + */ +static BOOL check_puttyagent_wm_copydata() +{ + HWND hwnd; + hwnd = FindWindow("Pageant", "Pageant"); + if (!hwnd) + return false; + else + return true; +} +#endif + #if MS_NAMEDPIPE static BOOL check_MSagent_namedpipe() { @@ -653,6 +678,9 @@ } #endif +/** + * PuTTY windows/agent-client.c agent_exists() \x82Ɠ\xAF\x93\x99 + */ BOOL putty_agent_exists() { #if PUTTY_NAMEDPIPE @@ -661,8 +689,7 @@ } #endif #if PUTTY_SHM - HWND hwnd = FindWindowA("Pageant", "Pageant"); - if (hwnd) { + if (check_puttyagent_wm_copydata()) { return TRUE; } #endif