+#ifndef NO_SECURITY\r
+/*\r
+ * Versions of Pageant prior to 0.61 expected this SID on incoming\r
+ * communications. For backwards compatibility, and more particularly\r
+ * for compatibility with derived works of PuTTY still using the old\r
+ * Pageant client code, we accept it as an alternative to the one\r
+ * returned from get_user_sid() in winpgntc.c.\r
+ */\r
+PSID get_default_sid(void)\r
+{\r
+ HANDLE proc = NULL;\r
+ DWORD sidlen;\r
+ PSECURITY_DESCRIPTOR psd = NULL;\r
+ PSID sid = NULL, copy = NULL, ret = NULL;\r
+\r
+ if ((proc = OpenProcess(MAXIMUM_ALLOWED, FALSE,\r
+ GetCurrentProcessId())) == NULL)\r
+ goto cleanup;\r
+\r
+ if (p_GetSecurityInfo(proc, SE_KERNEL_OBJECT, OWNER_SECURITY_INFORMATION,\r
+ &sid, NULL, NULL, NULL, &psd) != ERROR_SUCCESS)\r
+ goto cleanup;\r
+\r
+ sidlen = GetLengthSid(sid);\r
+\r
+ copy = (PSID)smalloc(sidlen);\r
+\r
+ if (!CopySid(sidlen, copy, sid))\r
+ goto cleanup;\r
+\r
+ /* Success. Move sid into the return value slot, and null it out\r
+ * to stop the cleanup code freeing it. */\r
+ ret = copy;\r
+ copy = NULL;\r
+\r
+ cleanup:\r
+ if (proc != NULL)\r
+ CloseHandle(proc);\r
+ if (psd != NULL)\r
+ LocalFree(psd);\r
+ if (copy != NULL)\r
+ sfree(copy);\r
+\r
+ return ret;\r
+}\r
+#endif\r
+\r