- /*
- * FIXME: use dwData somehow.
- */
- in = cds->lpData;
- inlen = cds->cbData;
- answer_msg(in, inlen, &out, &outlen);
- if (out) {
- id = 0;
- do {
- sprintf(mapname, "PageantReply%08x", ++id);
- filemap = CreateFileMapping(INVALID_HANDLE_VALUE,
- NULL, PAGE_READWRITE,
- 0, outlen+sizeof(int),
- mapname);
- } while (filemap == INVALID_HANDLE_VALUE);
- ret = MapViewOfFile(filemap, FILE_MAP_WRITE, 0, 0,
- outlen+sizeof(int));
- if (ret) {
- *((int *)ret) = outlen;
- memcpy(((int *)ret)+1, out, outlen);
- UnmapViewOfFile(ret);
- return id;
+ if (cds->dwData != AGENT_COPYDATA_ID)
+ return 0; /* not our message, mate */
+ mapname = (char *)cds->lpData;
+ if (mapname[cds->cbData - 1] != '\0')
+ return 0; /* failure to be ASCIZ! */
+#ifdef DEBUG_IPC
+ debug(("mapname is :%s:\r\n", mapname));
+#endif
+ filemap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, mapname);
+#ifdef DEBUG_IPC
+ debug(("filemap is %p\r\n", filemap));
+#endif
+ if (filemap != NULL && filemap != INVALID_HANDLE_VALUE) {
+ int rc;
+#ifndef NO_SECURITY
+ if (has_security) {
+ if ((proc = OpenProcess(MAXIMUM_ALLOWED, FALSE,
+ GetCurrentProcessId())) == NULL) {
+#ifdef DEBUG_IPC
+ debug(("couldn't get handle for process\r\n"));
+#endif
+ return 0;
+ }
+ if (getsecurityinfo(proc, SE_KERNEL_OBJECT,
+ OWNER_SECURITY_INFORMATION,
+ &procowner, NULL, NULL, NULL,
+ &psd2) != ERROR_SUCCESS) {
+#ifdef DEBUG_IPC
+ debug(("couldn't get owner info for process\r\n"));
+#endif
+ CloseHandle(proc);
+ return 0; /* unable to get security info */
+ }
+ CloseHandle(proc);
+ if ((rc = getsecurityinfo(filemap, SE_KERNEL_OBJECT,
+ OWNER_SECURITY_INFORMATION,
+ &mapowner, NULL, NULL, NULL,
+ &psd1) != ERROR_SUCCESS)) {
+#ifdef DEBUG_IPC
+ debug(("couldn't get owner info for filemap: %d\r\n", rc));
+#endif
+ return 0;
+ }
+#ifdef DEBUG_IPC
+ debug(("got security stuff\r\n"));
+#endif
+ if (!EqualSid(mapowner, procowner))
+ return 0; /* security ID mismatch! */
+#ifdef DEBUG_IPC
+ debug(("security stuff matched\r\n"));
+#endif
+ LocalFree(psd1);
+ LocalFree(psd2);
+ } else {
+#ifdef DEBUG_IPC
+ debug(("security APIs not present\r\n"));
+#endif