14 #define AGENT_COPYDATA_ID 0x804e50ba /* random goop */
15 #define AGENT_MAX_MSGLEN 8192
17 int agent_exists(void)
20 hwnd = FindWindow("Pageant", "Pageant");
27 void agent_cancel_query(agent_pending_query *q)
29 assert(0 && "Windows agent queries are never asynchronous!");
32 agent_pending_query *agent_query(
33 void *in, int inlen, void **out, int *outlen,
34 void (*callback)(void *, void *, int), void *callback_ctx)
39 unsigned char *p, *ret;
42 SECURITY_ATTRIBUTES sa, *psa;
43 PSECURITY_DESCRIPTOR psd = NULL;
49 hwnd = FindWindow("Pageant", "Pageant");
51 return NULL; /* *out == NULL, so failure */
52 mapname = dupprintf("PageantRequest%08x", (unsigned)GetCurrentThreadId());
58 * Make the file mapping we create for communication with
59 * Pageant owned by the user SID rather than the default. This
60 * should make communication between processes with slightly
61 * different contexts more reliable: in particular, command
62 * prompts launched as administrator should still be able to
63 * run PSFTPs which refer back to the owning user's
64 * unprivileged Pageant.
66 usersid = get_user_sid();
69 psd = (PSECURITY_DESCRIPTOR)
70 LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
72 if (p_InitializeSecurityDescriptor
73 (psd, SECURITY_DESCRIPTOR_REVISION) &&
74 p_SetSecurityDescriptorOwner(psd, usersid, FALSE)) {
75 sa.nLength = sizeof(sa);
76 sa.bInheritHandle = TRUE;
77 sa.lpSecurityDescriptor = psd;
86 #endif /* NO_SECURITY */
88 filemap = CreateFileMapping(INVALID_HANDLE_VALUE, psa, PAGE_READWRITE,
89 0, AGENT_MAX_MSGLEN, mapname);
90 if (filemap == NULL || filemap == INVALID_HANDLE_VALUE) {
92 return NULL; /* *out == NULL, so failure */
94 p = MapViewOfFile(filemap, FILE_MAP_WRITE, 0, 0, 0);
96 cds.dwData = AGENT_COPYDATA_ID;
97 cds.cbData = 1 + strlen(mapname);
101 * The user either passed a null callback (indicating that the
102 * query is required to be synchronous) or CreateThread failed.
103 * Either way, we need a synchronous request.
105 id = SendMessage(hwnd, WM_COPYDATA, (WPARAM) NULL, (LPARAM) &cds);
107 retlen = 4 + GET_32BIT(p);
108 ret = snewn(retlen, unsigned char);
110 memcpy(ret, p, retlen);
116 CloseHandle(filemap);