Commit Graph
87 Commits
Author SHA1 Message Date
Wez Furlong 5feadb347e ssh: libssh: improve diagnostic in case connect fails
show the host/port combo being attempted

refs: https://github.com/wez/wezterm/issues/2617
2022-10-11 08:19:40 -07:00
Wez Furlong 699d720a71 ssh: add trace logging when we send a signal 2022-08-31 20:40:06 -07:00
Wez Furlong 9721900b16 ssh: reduce some redundant logging around AcceptEnv
just show it once at warn level and drop it to debug after that.
2022-08-31 20:40:06 -07:00
Wez Furlong fdb7c557e9 ssh: close stdout, stderr bridges if child is done and there is no data
Inspecting the wezterm process with `lsof -p`, before and after closing
a pane with `CloseCurrentPane`, the same number of unix domain sockets
are open, which is bad.

This commit tries a bit harder to clean things up: if we got a process
exit condition we now remember that we had it, and, while processing
the IO for that channel, if we have no data for stdout or stderr
(respectively) and the channel exited, we close our end of the
socketpair to encourage EOF to be detected on the other end.

This is sufficient to restore the number of open files to the same
number wezterm had opened prior to opening that pane.

@chipsenkbeil: this might possibly be a factor in the issue you
reported, but I haven't had time to really dig into that yet!

refs: https://github.com/wez/wezterm/issues/2466
refs: https://github.com/wez/wezterm/issues/2456
2022-08-30 08:00:49 -07:00
Wez Furlong 53bc871147 ssh: correctly expand %h tokens in ssh config
refs: https://github.com/wez/wezterm/issues/2448
2022-08-23 10:32:07 -07:00
Wez Furlong e6421d1b72 pty: try_clone_writer -> take_writer
This breaking API change allows us to explicitly generate EOF when the
taken writer is dropped.

The examples have been updated to show how to manage read, write
and waiting without deadlock for both linux and windows.
Need to confirm that this is still good on macOS, but my
confidence is high.

I've also removed ssh2 support from this crate as part of this
change. We haven't used it directly in wezterm in a long while
and removing it from here means that there is slightly less code
to keep compiling over and over.

refs: https://github.com/wez/wezterm/discussions/2392
refs: https://github.com/wez/wezterm/issues/1396
2022-08-12 07:56:46 -07:00
Wez Furlong c8c3b8378a ssh: avoid busy loop when all channels are closed on the session
We need to notice when all of the streams associated with a channel are
closed and remove the channel from the set that we're polling in the
main loop, to avoid continually polling the closed descriptors.

Additionally, if the Session has been dropped, we know that we cannot
be asked to create any new channels, so if there are no more channels
then we can and should exit that dispatch loop and allow the resources
to be cleaned up.

refs: https://github.com/wez/wezterm/issues/1993#issuecomment-1130539934
2022-05-19 21:02:06 -07:00
Gregory Anders 68bd4f3a6b ssh: improve error message contexts 2022-04-15 20:53:07 -07:00
Gregory Anders c636a4d7a0 ssh: support BindAddress for libssh2 2022-04-15 20:53:07 -07:00
Gregory Anders 8560dbd2bb ssh: support BindAddress
This is already supported by libssh_rs.
2022-04-15 20:53:07 -07:00
Wez Furlong 0f6ee20b28 pty: ExitStatus now understands signals and impl Display
Improves the fidelity of the information in ExitStatus and shows it
in the wezterm exit_behavior output to clarify the status.
2022-04-09 06:15:54 -07:00
Wez Furlong 29995c7cb3 add wezterm.enumerate_ssh_hosts() helper
This helper extracts the concrete set of hosts and their configurations
from the ssh config, and arranges to reload the wezterm config if they
are changed.

This is useful when constructing ssh domain configs.

refs: https://github.com/wez/wezterm/discussions/1731
2022-03-18 07:48:12 -07:00
Chip Senkbeil caf504ee81 Re-export portable_pty::{PtySize, MasterPty, ChildKiller} as it is available in public API (#1603)
* Re-export portable_pty::PtySize as it is available in public API

* Re-export portable_pty::{MasterPty, ChildKiller} as those are both implemented by public structs from wezterm-ssh
2022-01-30 18:27:29 -07:00
Wez Furlong e4ed2c93e2 encoding my preferred import grouping in the rustfmt config
This uses an unstable option in rustfmt, you `cargo +nightly fmt`
needs to be used to format the code correctly.
2022-01-17 13:50:51 -07:00
Chip Senkbeil 1f17416e60 Support gating libssh-rs and ssh2 behind features of same name 2022-01-09 19:36:56 -08:00
Wez Furlong de13e17723 ssh: explicitly allow ssh-rsa keys in tests
It looks like the debian 9 test failures with libssh are the
same underlying issue as https://github.com/wez/wezterm/issues/1262

Poking around in the debug output, and then spelunking through the code,
we can use the `pubkeyacceptedtypes` ssh config option to add the key
type to the list of keys.  This doesn't appear to be a documented
option in the current versions of openssh.

I'm not 100% sure that this is right, but it's worth a shot.
2021-12-15 22:05:24 -07:00
Wez Furlong d6ef3c67c5 ssh: improve diagnostics to debug failing integration test 2021-12-15 11:39:00 -07:00
Wez Furlong 8b58f28125 wezterm-ssh: default to libssh2. mux: revise bootstrap_via_ssh
This commit revises the tls domain bootstrap via ssh code and
makes it work again from a windows client.
2021-12-15 11:10:16 -07:00
Wez Furlong f398f333cd ssh: make -v option work on Windows, adjust config overlaying
Route logging via the `log` crate because on Windows there is
no stderr visible to libssh.

libssh will override any explicitly set options when it parses
the config file, so we need to apply those after we've loaded it.
2021-12-15 09:18:00 -07:00
Wez Furlong 421bcd25c1 ssh: allow partial auth
Some systems employ multi-stage authentication, so allow for that
to work.
2021-12-15 08:58:21 -07:00
Wez Furlong 7926c31209 pty: introduce ChildKiller trait
In the mux layer, we have some code that takes a `Child` and then
does a bit of naughty reaching through the abstraction to get at
the pid/handle of the child so that we can send it signals even
if the child is itself mutably (and thus exclusively) borrowed
for the purposes of waiting.

That worked fine for local processes spawned in the mux, but we also
use LocalPane to wrap around arbitrary `Child`ren, such as Ssh,
that are not local and that don't have a local process id, which
meant that this hack wouldn't work for them.

To make things a bit worse, those ssh ptys were used to ssh2 days
where we didn't have a way to signal the remote process and just
did nothing, leading to confusing situations such as
https://github.com/wez/wezterm/issues/1197

This commit graduates the hack mentioned in the first paragraph
to its own ChildKiller trait.  This makes the concept of waiting
for the Child distinct from signalling it and explicitly allows
getting a separate object that can be used for signalling.

With that in place, we're forced to implement something appropriate
for the ssh pty implementations; one in the pty crate itself,
one in wezterm-ssh and the wrapper that we use in the mux crate.

The upshot of this is that the `CloseCurrentPane` action now operates
correctly on panes that were the result of split operations.
2021-12-11 08:40:26 -07:00
nick black 3092443f89 provide missing positional arguments to diagnostics 2021-11-19 14:47:05 -08:00
Wez Furlong b8ff61da5b ssh: allow wezterm ssh -v to log verbose diagnostics to stderr
Feels generally useful
2021-10-25 15:56:36 -07:00
Wez Furlong 124248028f ssh: enable proxycommand overrides via command line for libssh backend 2021-10-21 07:18:26 -07:00
Wez Furlong 561eaa69be ssh: adopt dispatch helper in a couple more places 2021-10-19 20:33:30 -07:00
Wez Furlong 5ada8e20cc ssh: adopt dispatch helper for ssh file and dir requests too
@chipsenkbeil: I spotted a latent bug in here that got fixed as
a side effect of this change.  For `write_file` and possibly others,
reply.try_send was only called in the case where file_id was valid.
For an invalid id, I think the caller could hang.

Not sure if this was a problem in practice, but I wonder if it might
have contributed to some of the weird state issues you mentioned.
2021-10-19 20:33:30 -07:00
Wez Furlong 74b763a3f6 ssh: remove some boilerplate 2021-10-19 20:33:30 -07:00
Wez Furlong 199fd6f52f ssh: use only the first known host location for libssh 2021-10-19 20:33:30 -07:00
Wez Furlong 8be442e39b ssh: can now pass e2e tests using libssh backend 2021-10-19 20:33:30 -07:00
Wez Furlong 390fcc56ca ssh: stub out DirWrap::read_dir for libssh 2021-10-19 20:33:30 -07:00
Wez Furlong e3f5174dcc ssh: introduce separate Dir and DirWrap types 2021-10-19 20:33:30 -07:00
Wez Furlong 9d44cc1720 ssh: introduce SftpWrap 2021-10-19 20:33:30 -07:00
Wez Furlong a6022f5c65 ssh: allow selecting libssh or ssh2 backend via config
Pass this via the ssh option overrides:

```
wezterm ssh -o wezterm_ssh_backend=libssh hostname
```
2021-10-19 20:33:30 -07:00
Wez Furlong 1f073db776 ssh: flatten out session module 2021-10-19 20:33:30 -07:00
Wez Furlong 75f946c22c ssh: split SessionWrap out 2021-10-19 20:33:30 -07:00
Wez Furlong 65eaa44b0d ssh: split FileWrap out 2021-10-19 20:33:30 -07:00
Wez Furlong e8b83b29c9 ssh: split ChannelWrap out 2021-10-19 20:33:30 -07:00
Wez Furlong 228df03059 ssh: move sftp module to top level
was getting too deep in there!
2021-10-19 20:33:30 -07:00
Wez Furlong 44bbfd2894 ssh: split SessionInner, out 2021-10-19 20:33:30 -07:00
Wez Furlong bd47566681 ssh: Improve some logging/diagnostics 2021-10-19 20:33:30 -07:00
Wez Furlong a8b64a2756 Run with libssh
This works, but on macOS, there is a segfault in openssl when the
session is closed... I'm going to try this on Linux to see if it
is consistent behavior and ponder next steps.
2021-10-19 20:33:30 -07:00
Wez Furlong 0bf50924b1 ssh: stub out libssh impl 2021-10-19 20:33:30 -07:00
Wez Furlong f1e5c59566 ssh: introduce wrapper enum
This is a pre-cursor step to adding libssh support
2021-10-19 20:33:30 -07:00
Wez Furlong 2da43e3666 ssh: unwrap -> error handling
The port number is guaranteed to be set in the config parser,
just like for the host and user, so the unwrap is "OK", but it's
less brittle to handle the error consistent with the others here.
2021-10-10 15:03:21 -07:00
Chip Senkbeil 56c366cc45 Remove Metadata::len and Metadata::is_readonly; replace sftp unwrap() with expect() 2021-10-10 14:54:45 -07:00
Chip Senkbeil 2415a44d74 Switch to camino::{Utf8PathBuf, Utf8Path} 2021-10-10 14:54:45 -07:00
Chip Senkbeil 1ff2a1eb82 Add bitflags type safety to sftp flags 2021-10-10 14:54:45 -07:00
Chip Senkbeil d15789d2c0 Finish refactoring names of methods based on wez feedback 2021-10-10 14:54:45 -07:00
Chip SenkbeilandWez Furlong c3516341cb Apply renames from code review (needs full refactoring)
Co-authored-by: Wez Furlong <wez@wezfurlong.org>
2021-10-10 14:54:45 -07:00
Chip Senkbeil 072bb1c470 Create SftpError type and associated structs to provide more verbose errors for sftp 2021-10-10 14:54:45 -07:00