10 #include "pageant.h" /* for AGENT_MAX_MSGLEN */
16 #define AGENT_COPYDATA_ID 0x804e50ba /* random goop */
18 int agent_exists(void)
21 hwnd = FindWindow("Pageant", "Pageant");
28 void agent_cancel_query(agent_pending_query *q)
30 assert(0 && "Windows agent queries are never asynchronous!");
33 agent_pending_query *agent_query(
34 void *in, int inlen, void **out, int *outlen,
35 void (*callback)(void *, void *, int), void *callback_ctx)
40 unsigned char *p, *ret;
43 SECURITY_ATTRIBUTES sa, *psa;
44 PSECURITY_DESCRIPTOR psd = NULL;
50 hwnd = FindWindow("Pageant", "Pageant");
52 return NULL; /* *out == NULL, so failure */
53 mapname = dupprintf("PageantRequest%08x", (unsigned)GetCurrentThreadId());
59 * Make the file mapping we create for communication with
60 * Pageant owned by the user SID rather than the default. This
61 * should make communication between processes with slightly
62 * different contexts more reliable: in particular, command
63 * prompts launched as administrator should still be able to
64 * run PSFTPs which refer back to the owning user's
65 * unprivileged Pageant.
67 usersid = get_user_sid();
70 psd = (PSECURITY_DESCRIPTOR)
71 LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
73 if (p_InitializeSecurityDescriptor
74 (psd, SECURITY_DESCRIPTOR_REVISION) &&
75 p_SetSecurityDescriptorOwner(psd, usersid, FALSE)) {
76 sa.nLength = sizeof(sa);
77 sa.bInheritHandle = TRUE;
78 sa.lpSecurityDescriptor = psd;
87 #endif /* NO_SECURITY */
89 filemap = CreateFileMapping(INVALID_HANDLE_VALUE, psa, PAGE_READWRITE,
90 0, AGENT_MAX_MSGLEN, mapname);
91 if (filemap == NULL || filemap == INVALID_HANDLE_VALUE) {
93 return NULL; /* *out == NULL, so failure */
95 p = MapViewOfFile(filemap, FILE_MAP_WRITE, 0, 0, 0);
97 cds.dwData = AGENT_COPYDATA_ID;
98 cds.cbData = 1 + strlen(mapname);
102 * The user either passed a null callback (indicating that the
103 * query is required to be synchronous) or CreateThread failed.
104 * Either way, we need a synchronous request.
106 id = SendMessage(hwnd, WM_COPYDATA, (WPARAM) NULL, (LPARAM) &cds);
108 retlen = 4 + GET_32BIT(p);
109 ret = snewn(retlen, unsigned char);
111 memcpy(ret, p, retlen);
117 CloseHandle(filemap);