1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00
putty-source/windows/CMakeLists.txt
Simon Tatham 0ad344ca32 Windows Pageant: make atomic client/server decision.
In the previous state of the code, we first tested agent_exists() to
decide whether to be the long-running Pageant server or a short-lived
client; then, during the command-line parsing loop, we prompted for
passphrases to add keys presented on the command line (to ourself or
the server, respectively); *then* we set up the named pipe and
WM_COPYDATA receiver window to actually start functioning as a server,
if we decided that was our role.

A consequence is that if a user started up two Pageants each with an
encrypted key on the command line, there would be a race condition:
each one would decide that it was _going_ to be the server, then
prompt for a passphrase, and then try to set itself up as the server
once the passphrase is entered. So whichever one's passphrase prompt
was answered second would add its key to its own internal data
structures, then fail to set up the server's named pipe, terminate
with an error, and end up not having added its key to the _surviving_
server.

This change reorders the setup steps so that the command-line parsing
loop does not add the keys immediately; instead it merely caches the
key filenames provided. Then we make the decision about whether we're
the server, and set up both the named pipe and WM_COPYDATA window if
we are; and finally, we go back to our list of key filenames and
actually add them, either to ourself (if we're the server) or to some
other Pageant (if we're a client).

Moreover, the decision about whether to be the server is now wrapped
in an interprocess mutex similar to the one used in connection
sharing, which means that even if two or more Pageants are started up
as close to simultaneously as possible, they should avoid a race
condition and successfully manage to agree on exactly one of
themselves to be the server. For example, a user reported that this
could occur if you put shortcuts to multiple private key files in your
Windows Startup folder, so that they were all launched simultaneously
at startup.

One slightly odd behaviour that remains: if the server Pageant has to
prompt for private key passphrases at startup, then it won't actually
start _servicing_ requests from other Pageants until it's finished
dealing with its own prompts. As a result, if you do start up two
Pageants at once each with an encrypted key file on its command line,
the second one won't even manage to present its passphrase prompt
until the first one's prompt is dismissed, because it will block
waiting for the initial check of the key list. But it will get there
in the end, so that's only a cosmetic oddity.

It would be nice to arrange that Pageant GUI operations don't block
unrelated agent requests (e.g. by having the GUI and the agent code
run in separate threads). But that's a bigger problem, not specific to
startup time - the same thing happens if you interactively load a key
via Pageant's file dialog. And it would require a major reorganisation
to fix that fully, because currently the GUI code depends on being
able to call _internal_ Pageant query functions like
pageant_count_ssh2_keys() that don't work by constructing an agent
request at all.
2022-01-03 12:21:39 +00:00

177 lines
5.0 KiB
CMake

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
add_sources_from_current_dir(utils
utils/agent_mutex_name.c
utils/agent_named_pipe_name.c
utils/arm_arch_queries.c
utils/cryptoapi.c
utils/defaults.c
utils/dll_hijacking_protection.c
utils/dputs.c
utils/escape_registry_key.c
utils/filename.c
utils/fontspec.c
utils/getdlgitemtext_alloc.c
utils/get_system_dir.c
utils/get_username.c
utils/interprocess_mutex.c
utils/is_console_handle.c
utils/load_system32_dll.c
utils/ltime.c
utils/makedlgitemborderless.c
utils/make_spr_sw_abort_winerror.c
utils/message_box.c
utils/minefield.c
utils/open_for_write_would_lose_data.c
utils/pgp_fingerprints_msgbox.c
utils/platform_get_x_display.c
utils/registry_get_string.c
utils/request_file.c
utils/security.c
utils/split_into_argv.c
utils/version.c
utils/win_strerror.c
unicode.c)
if(NOT HAVE_STRTOUMAX)
add_sources_from_current_dir(utils utils/strtoumax.c)
endif()
add_sources_from_current_dir(eventloop
cliloop.c handle-wait.c)
add_sources_from_current_dir(console
select-cli.c nohelp.c console.c)
add_sources_from_current_dir(settings
storage.c)
add_sources_from_current_dir(network
network.c handle-socket.c named-pipe-client.c named-pipe-server.c local-proxy.c x11.c)
add_sources_from_current_dir(sshcommon
noise.c)
add_sources_from_current_dir(sshclient
agent-client.c gss.c sharing.c)
add_sources_from_current_dir(sftpclient
sftp.c)
add_sources_from_current_dir(otherbackends
serial.c)
add_sources_from_current_dir(agent
agent-client.c)
add_sources_from_current_dir(guiterminal
dialog.c controls.c config.c printing.c jump-list.c sizetip.c)
add_dependencies(guiterminal generated_licence_h) # dialog.c uses licence.h
# This object awkwardly needs to live in the network library as well
# as the eventloop library, in case it didn't get pulled in from the
# latter before handle-socket.c needed it.
add_library(handle-io OBJECT
handle-io.c)
target_sources(eventloop PRIVATE $<TARGET_OBJECTS:handle-io>)
target_sources(network PRIVATE $<TARGET_OBJECTS:handle-io>)
add_library(guimisc STATIC
select-gui.c)
add_executable(pageant
pageant.c
help.c
pageant.rc)
add_dependencies(pageant generated_licence_h)
target_link_libraries(pageant
guimisc eventloop agent network crypto utils
${platform_libraries})
set_target_properties(pageant PROPERTIES
WIN32_EXECUTABLE ON
LINK_FLAGS "${LFLAG_MANIFEST_NO}")
installed_program(pageant)
add_sources_from_current_dir(plink no-jump-list.c nohelp.c plink.rc)
add_dependencies(plink generated_licence_h)
add_sources_from_current_dir(pscp no-jump-list.c nohelp.c pscp.rc)
add_dependencies(pscp generated_licence_h)
add_sources_from_current_dir(psftp no-jump-list.c nohelp.c psftp.rc)
add_dependencies(psftp generated_licence_h)
add_sources_from_current_dir(psocks nohelp.c)
add_executable(putty
window.c
putty.c
help.c
putty.rc)
be_list(putty PuTTY SSH SERIAL OTHERBACKENDS)
add_dependencies(putty generated_licence_h)
target_link_libraries(putty
guiterminal guimisc eventloop sshclient otherbackends settings network crypto
utils
${platform_libraries})
set_target_properties(putty PROPERTIES
WIN32_EXECUTABLE ON
LINK_FLAGS "${LFLAG_MANIFEST_NO}")
installed_program(putty)
add_executable(puttytel
window.c
putty.c
help.c
${CMAKE_SOURCE_DIR}/stubs/nogss.c
${CMAKE_SOURCE_DIR}/stubs/norand.c
${CMAKE_SOURCE_DIR}/proxy/nocproxy.c
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c
puttytel.rc)
be_list(puttytel PuTTYtel SERIAL OTHERBACKENDS)
add_dependencies(puttytel generated_licence_h)
target_link_libraries(puttytel
guiterminal guimisc eventloop otherbackends settings network utils
${platform_libraries})
set_target_properties(puttytel PROPERTIES
WIN32_EXECUTABLE ON
LINK_FLAGS "${LFLAG_MANIFEST_NO}")
installed_program(puttytel)
add_executable(puttygen
puttygen.c
${CMAKE_SOURCE_DIR}/stubs/notiming.c
noise.c
no-jump-list.c
storage.c
help.c
${CMAKE_SOURCE_DIR}/sshpubk.c
${CMAKE_SOURCE_DIR}/sshrand.c
controls.c
puttygen.rc)
add_dependencies(puttygen generated_licence_h)
target_link_libraries(puttygen
keygen guimisc crypto utils
${platform_libraries})
set_target_properties(puttygen PROPERTIES
WIN32_EXECUTABLE ON
LINK_FLAGS "${LFLAG_MANIFEST_NO}")
installed_program(puttygen)
if(HAVE_CONPTY)
add_executable(pterm
window.c
pterm.c
help.c
conpty.c
${CMAKE_SOURCE_DIR}/stubs/nogss.c
${CMAKE_SOURCE_DIR}/stubs/norand.c
${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c
pterm.rc)
be_list(pterm pterm)
add_dependencies(pterm generated_licence_h)
target_link_libraries(pterm
guiterminal guimisc eventloop settings network utils
${platform_libraries})
set_target_properties(pterm PROPERTIES
WIN32_EXECUTABLE ON
LINK_FLAGS "${LFLAG_MANIFEST_NO}")
installed_program(pterm)
else()
message("ConPTY not available; cannot build Windows pterm")
endif()
add_executable(test_split_into_argv
utils/split_into_argv.c)
target_compile_definitions(test_split_into_argv PRIVATE TEST)
target_link_libraries(test_split_into_argv utils ${platform_libraries})