1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00
Commit Graph

57 Commits

Author SHA1 Message Date
Ben Harris
09095a7d92 Avoid treating non-X GDK display names as X ones
When running on Wayland, gdk_display_get_name() can return things like
"wayland-0" rather than valid X display names.  PuTTY nonetheless
treated them as X display names, meaning that when running under
Wayland, pterm would set DISPLAY to "wayland-0" in subprocesses, and
PuTTY's X forwarding wouldn't work properly.

To fix this, places that call gdk_display_get_name() now only do so on
displays for which GDK_IS_X_DISPLAY() is true.  As with
GDK_IS_X_WINDOW(), this requires some backward-compatibility for GDK
versions where everything is implicitly running on X.

To make this work usefully, pterm now also won't unset DISPLAY if it
can't get an X display name and instead will pass through whatever value
of DISPLAY it received.  I think that's better behaviour anyway.

There are two separate parts of PuTTY that call gdk_display_get_name().
platform_get_x_display() in unix/putty.c is used for X forwarding, while
gtk_seat_get_x_display() in unix/window.c is used used for setting DISPLAY
and recording in utmp.  I've updated both of them.
2024-12-15 00:07:21 +00:00
Simon Tatham
6cf6682c54 Rewrite some manual char-buffer-handling code.
In the course of recent refactorings I noticed a couple of cases where
we were doing old-fashioned preallocation of a char array with some
conservative maximum size, then writing into it via *p++ or similar
and hoping we got the calculation right.

Now we have strbuf and dupcat, so we shouldn't ever have to do that.
Fixed as many cases as I could find by searching for allocations of
the form 'snewn(foo, char)'.

Particularly worth a mention was the Windows GSSAPI setup code, which
was directly using the Win32 Registry API, and looks much more legible
using the windows/utils/registry.c wrappers. (But that was why I had
to enhance them in the previous commit so as to be able to open
registry keys read-only: without that, the open operation would
actually fail on this key, which is not user-writable.)

Also unix/askpass.c, which was doing a careful reallocation of its
buffer to avoid secrets being left behind in the vacated memory -
which is now just a matter of ensuring we called strbuf_new_nm().
2022-09-14 16:10:29 +01:00
Simon Tatham
04c1617f20 Formatting: realign labels and case/default statements.
My aim has always been to have those back-dented by 2 spaces (half an
indent level) compared to the statements around them, so that in
particular switch statements have distinct alignment for the
statement, the cases and the interior code without consuming two whole
indent levels.

This patch sweeps up all the violations of that principle found by my
bulk-reindentation exercise.
2022-08-03 20:48:46 +01:00
Jacob Nevins
92881f2066 Define OMIT_UTMP if there's no utmpx.h.
Without this, the build of e.g. psusan would fail on systems without
that header (such as Termux on Android).

This is similar to how things were pre-cmake, but not identical. We used
to treat lack of updwtmpx() as a reason to OMIT_UTMP (as of f0dfa73982),
but usage of that function got conditionalised in c19e7215dd, so I
haven't restored that exclusion.
2022-05-18 18:51:00 +01:00
Simon Tatham
f780a45c57 Proper backlog handling in Unix pty backend.
If the Seat that the pty backend is talking to starts to back up, then
we ought to temporarily stop reading from the pty device, to pass that
back-pressure on to whatever's running in the terminal.

Previously, this didn't matter because a Seat running a GUI terminal
never backed up anyway. But now it does, so we should support it all
the way through the system.
2021-12-20 13:14:40 +00:00
Simon Tatham
76dc28552c Add memsets after allocation of all Backend implementors.
Now every struct that implements the Backend trait is completely
cleared before we start initialising any of its fields. This will mean
I can add new fields that default to 0 or NULL, without having to mess
around initialising them explicitly everywhere.
2021-10-30 17:28:28 +01:00
Simon Tatham
5374444879 Lowercase version of BackendVtable's displayname.
The current 'displayname' field is designed for presenting in the
config UI, so it starts with a capital letter even when it's not a
proper noun. If I want to name the backend in the middle of a
sentence, I'll need a version that starts with lowercase where
appropriate.

The old field is renamed displayname_tc, to avoid ambiguity.
2021-10-24 09:59:05 +01:00
Simon Tatham
c336643576 Separate backend_send from backend_sendbuffer.
On a similar theme of separating the query operation from the
attempted change, backend_send() now no longer has the side effect of
returning the current size of the send buffer. Instead, you have to
call backend_sendbuffer() every time you want to know that.
2021-09-12 09:52:46 +01:00
Simon Tatham
c06c9c730f Fill in missing implementation of pty_sendbuffer.
Going through all the backends' send() and sendbuffer() routines, I
noticed that the Unix pty backend is the only one where the return
value from send() doesn't match what sendbuffer() would tell you,
apparently because sendbuffer() was a stub implementation that I never
got round to filling in properly.

But pty masters _can_ back up, and if they do, we should return the
appropriate data.
2021-09-12 09:52:46 +01:00
Simon Tatham
6791bdc9b6 Don't #include <utmp.h> if it doesn't exist.
A FreeBSD user reports that it doesn't exist there.
2021-05-13 18:40:47 +01:00
Simon Tatham
f39c51f9a7 Rename most of the platform source files.
This gets rid of all those annoying 'win', 'ux' and 'gtk' prefixes
which made filenames annoying to type and to tab-complete. Also, as
with my other recent renaming sprees, I've taken the opportunity to
expand and clarify some of the names so that they're not such cryptic
abbreviations.
2021-04-26 18:00:01 +01:00
Simon Tatham
c64ad3bb0c Rename some of the more stupidly named files in the Unix back end.
Notably pterm.c, which was a sensible name right at the start but
became a misnomer as soon as I created Unix PuTTY.

[originally from svn r5053]
2004-12-31 13:02:46 +00:00
Ben Harris
bb4b9039b4 If we're going to define _XOPEN_SOURCE, we should at least define it to a
version that includes putenv().  Make it 600 (the current one) for good
measure.

[originally from svn r5048]
2004-12-30 17:29:54 +00:00
Simon Tatham
b0bf176dfb Loose end from r5031: the Kex panel should only be displayed in
mid-session if we are not using SSHv1. I've done this by introducing
a generic `cfg_info' function which every back end can use to
communicate an int's worth of data to setup_config_box; in SSH
that's the protocol version in use, and in everything else it's
currently zero.

[originally from svn r5040]
[r5031 == d77102a8d5]
2004-12-29 12:32:25 +00:00
Simon Tatham
b3b70d749f Jacob has pointed out why SIGCHLD was blocked, so I've updated the
comment when I unblock it in pty.c to reflect reality. Also I've
moved block_signal() out of pterm.c into signal.c, so I can
conveniently use it for unblocking SIGCHLD rather than having to
reinvent it in pty.c.

[originally from svn r5006]
2004-12-17 14:25:53 +00:00
Simon Tatham
ebf507497d Apparently SIGCHLD is blocked by default in processes run in a
pterm, which was breaking my bash job notification patch. This is
apparently not the case for xterm, so I've fiddled with it. Not
entirely sure _why_ it did this in the first place, but there we go.

[originally from svn r4997]
2004-12-17 09:43:09 +00:00
Simon Tatham
7ecf13564a New timing infrastructure. There's a new function schedule_timer()
which pretty much any module can call to request a call-back in the
future. So terminal.c can do its own handling of blinking, visual
bells and deferred screen updates, without having to rely on
term_update() being called 50 times a second (fixes: pterm-timer);
and ssh.c and telnet.c both invoke a new module pinger.c which takes
care of sending keepalives, so they get sent uniformly in all front
ends (fixes: plink-keepalives, unix-keepalives).

[originally from svn r4906]
[this svn revision also touched putty-wishlist]
2004-11-27 13:20:21 +00:00
Simon Tatham
1aa64afc30 I think rjk meant setpgid', not setpgrp'.
[originally from svn r4897]
2004-11-24 11:42:45 +00:00
Simon Tatham
4f197b872e RJK's OS X portability patch:
- initialise blank mbstate_t using memset rather than an ad-hoc
   initialiser.
 - expand the OMIT_UTMP ifdefs to enclose a load of entire functions
   that would generate `static function never called' warnings if
   left as empty shells.
 - couple of other fiddly things.

[originally from svn r4896]
2004-11-24 11:36:08 +00:00
Simon Tatham
859d92a577 Moved the environment variables config block out of the Telnet panel
into the Connection panel, and implemented support for the SSH2
"env" request. (I haven't yet found a server which accepts this
request, so although I've visually checked the packet log and it
looks OK, I haven't yet been able to do a full end-to-end test.)
Also, the `pty' backend reads this data and does a series of
`putenv' commands before launching the shell or application.

This is mostly because in last week's UTF-8 faffings I got
thoroughly sick of typing `export LANG=en_GB.UTF-8' every time I
started a new testing pterm, and it suddenly occurred to me that
this would be precisely the sort of thing you'd want to have pterm
set up for you, particularly since you can configure it alongside
the translation settings and so you can ensure they match up
properly.

[originally from svn r4645]
2004-10-16 10:56:54 +00:00
Jacob Nevins
df66432b5d Patch from Kurt Roeckx: apparently on Debian amd64, the ut_time member of
struct utmp is not equivalent to time_t (it's 32-bit). From Debian bug#265910.

[originally from svn r4459]
2004-08-16 09:38:12 +00:00
Jacob Nevins
20f433efac Add a configuration option for TCP keepalives (SO_KEEPALIVE), default off.
No very good reason, but I've occasionally wanted to frob it to see if it
makes any difference to problems I'm having, and it was easy.

Tested that it does actually cause keepalives on Windows (with tcpdump);
should also work on Unix. Not implemented on Mac (does nothing), but then
neither is TCP_NODELAY.

Quite a big checkin, much of which is adding `keepalive' alongside `nodelay'
in network function calls.

[originally from svn r4309]
2004-06-20 17:07:38 +00:00
Simon Tatham
80c3a23abc I think I've just fixed Debian bug #166396. The +ut option was
causing pty_utmp_helper_pipe to be closed, but its fd was kept
around even when stale, and closed again when the main child process
terminated - by which time the fd number had been reused for a
rather more vital fd, which GTK didn't appreciate having closed
under its feet. Hence, spin on POLLNVAL. Should now be sorted.

[originally from svn r3185]
2003-05-11 12:28:53 +00:00
Simon Tatham
6bb121ecb9 Colin's const-fixing Patch Of Death. Seems to build fine on Windows
as well as Unix, so it can go in.

[originally from svn r3162]
2003-05-04 14:18:18 +00:00
Simon Tatham
bc4e41154a Close On Exit and Warn On Close fixes: (a) pty_reconfig needs to
remember changes in COE so it knows whether to print a message, and
(b) once the session has already ended, Warn On Close should shut up.

[originally from svn r3102]
2003-04-12 08:27:03 +00:00
Simon Tatham
3bd0415579 Turned the old `Telnet Command' System-submenu into a more general
`Special Command' menu, in which any backend can place its own list
of magical things the user might want to ask the backend to do. In
particular I've implemented the recently proposed "break" extension
in SSH2 using this mechanism.
NB this checkin slightly breaks the Mac build, since it needs to
provide at least a stub form of update_specials_menu().

[originally from svn r3054]
2003-04-04 20:21:05 +00:00
Simon Tatham
a3428ae953 Having created and used uxsel, it actually turns out to be
practically trivial to put all the pieces together and create a
working prototype of Unix PuTTY! It's missing a lot of things -
notably GUI request boxes for host keys and logfiles and so forth,
the Event Log, mid-session reconfiguration, session loading and
saving, sensible population of the character sets drop-down list and
probably other fiddly little things too - but it will put up a
config box and then create a GUI window containing an SSH connection
to the host you specified, so it's _basically_ there. Woo!

[originally from svn r3020]
2003-03-29 19:52:50 +00:00
Simon Tatham
5107780c54 pterm now uses the new uxsel module, so it's one step closer to
being able to be a PuTTY as well as a pterm. In the process I've
also moved icky things like actually reading from the pty fd and
printing the `terminated on signal' messages into pty.c where they
obviously should have been in the first place. Also there's been one
interesting repercussion in the terminal code: terminal.c's
from_backend now calls term_out() directly rather than expecting the
front end to call it afterwards. This has had the entertaining side
effect of fixing a Windows-specific bug whereby activity in a port
forwarding through a PuTTY with a blinking cursor caused the cursor
to blink to ON (!!!!). So, a surprisingly far-reaching checkin as it
turns out...

[originally from svn r3017]
2003-03-29 18:30:14 +00:00
Simon Tatham
d36a4c3685 Introduced wrapper macros snew(), snewn() and sresize() for the
malloc functions, which automatically cast to the same type they're
allocating the size of. Should prevent any future errors involving
mallocing the size of the wrong structure type, and will also make
life easier if we ever need to turn the PuTTY core code from real C
into C++-friendly C. I haven't touched the Mac frontend in this
checkin because I couldn't compile or test it.

[originally from svn r3014]
2003-03-29 16:14:26 +00:00
Simon Tatham
83da92826e Richard B's patch to add WINDOWID support to pterm.
[originally from svn r2912]
2003-03-06 12:57:37 +00:00
Ben Harris
81ada5f24f Add a stub "free" routine for pterm. Thanks to rjk.
[originally from svn r2666]
2003-01-20 20:10:07 +00:00
Simon Tatham
f49c8c5a07 The back ends now contain their own copies of the Config structure,
and have a function to pass in a new one. (Well, actually several
back ends don't actually bother to do this because they need nothing
out of Config after the initial setup phase, but they could if they
wanted to.)

[originally from svn r2561]
2003-01-12 14:48:29 +00:00
Simon Tatham
d6739ada35 Another signal-handling refinement from RJK: the SIGCHLD handler
should be prepared to reap more than one child per invocation if
necessary, since we do after all have two.

[originally from svn r2183]
2002-11-02 16:05:26 +00:00
Simon Tatham
93e9fadc75 RJK's general signal-handling robustness patch. Should fix the weird
spin behaviour occasionally seen after pterm's child process dies.

[originally from svn r2181]
2002-11-02 14:35:57 +00:00
Simon Tatham
4756c15fc9 Yet more global-removal. The static variables in logging.c are now
absent, and also (I think) all the frontend request functions (such
as request_resize) take a context pointer, so that multiple windows
can be handled sensibly. I wouldn't swear to this, but I _think_
that only leaves the Unicode stuff as the last stubborn holdout.

[originally from svn r2147]
2002-10-26 12:58:13 +00:00
Simon Tatham
0b2523eeda Line discipline module now uses dynamically allocated data. Also
fixed one or two other minor problems.

[originally from svn r2141]
2002-10-26 10:16:19 +00:00
Simon Tatham
6e2a0c079b pty backend now supports the changed function interface, so pterm
now compiles and runs again after the major destabilisation.
Unfortunately it wasn't feasible to actually encapsulate all of the
pty backend's data, since the utmp helper and the need to fork and
drop privileges before doing anything else at all rather confuses
matters. So the data handle passed around to the pty backend is a
null pointer, and the pty backend is just as global-ridden as it
always has been. Shame, but such is life.

[originally from svn r2128]
2002-10-25 11:50:51 +00:00
Simon Tatham
bdb47167d1 Implement handling of all Close On Exit modes. Default is to close
only on clean exit, which is a departure from most xterm-alikes but
Ian reckons people will love me for it. If this turns out to be
wrong, we can always change the default for Unix.

[originally from svn r2120]
2002-10-23 14:21:12 +00:00
Simon Tatham
a9bd716df8 Cleanups from yesterday's destabilisation: lots of stuff in
terminal.c was apparently relying on implicit initialisation to
zero, and also I've removed the backends' dependency on terminal.h
by having terminal sizes explicitly passed in to back->size().

[originally from svn r2117]
2002-10-23 12:41:35 +00:00
Simon Tatham
0a80c983e2 Major destabilisation, phase 1. In this phase I've moved (I think)
all the global and function-static variables out of terminal.c into
a dynamically allocated data structure. Note that this does not yet
confer the ability to run more than one of them in the same process,
because other things (the line discipline, the back end) are still
global, and also in particular the address of the dynamically
allocated terminal-data structure is held in a global variable
`term'. But what I've got here represents a reasonable stopping
point at which to check things in. In _theory_ this should all still
work happily, on both Unix and Windows. In practice, who knows?

[originally from svn r2115]
2002-10-22 16:11:33 +00:00
Simon Tatham
5ce13aad0f Stop `pterm -ut-' leaving the unnecessary utmp helper as a zombie
process (Debian bug #165887).

[originally from svn r2113]
2002-10-22 13:26:57 +00:00
Simon Tatham
45c494ff9d Make sure SIGINT and SIGQUIT haven't been nobbled in our child
process by weird POSIX-required shell behaviour.

[originally from svn r2110]
2002-10-21 23:01:34 +00:00
Simon Tatham
068da38044 Don't bother closing fds 0-2 before dup2ing over them; there's no
need, and it means we always have a valid open stderr.

[originally from svn r2109]
2002-10-21 23:00:18 +00:00
Simon Tatham
1aed45b4e1 Fix utmp and pty handling so that GTK never complains about running
set[ug]id. All privs-requiring pty operations are done at the very
start of the run, then privs are dropped before initialising GTK.
Utmp is handled by forking a still-privileged subprocess at this
point, and later asking it (through a pipe) to stamp utmp. The
subprocess cleans up utmp on exit, which has the additional
advantage that if the main pterm process suffers some sort of
unexpected termination (up to and including SIGKILL) the subprocess
can still mop up utmp.

[originally from svn r2082]
2002-10-16 12:17:51 +00:00
Simon Tatham
07a69c5245 Configure the pty so that it agrees with our idea of whether
Backspace sends ^H or ^?.

[originally from svn r2076]
2002-10-15 18:36:18 +00:00
Simon Tatham
e18cf6b714 Don't forget to initialise the pixel size parameters of the window
as passed to the pty...

[originally from svn r2064]
2002-10-15 15:16:21 +00:00
Simon Tatham
0c011dcbe0 Introduce the ability to control whether the shell run in pterm is a
login shell or not. Also moved these new pieces of configuration
into the Config structure, though they won't stay there forever
since they will need to be moved out into platform-dependent config.

[originally from svn r2060]
2002-10-15 13:07:18 +00:00
Simon Tatham
0813c25bf6 Finish up utmp processing: add the -ut- command-line option to
suppress stamping it at all. (I suppose this ought to be part of the
cfg structure really.)

[originally from svn r2059]
2002-10-15 12:42:58 +00:00
Simon Tatham
6118021749 Support for utmp, wtmp and lastlog. Probably not terribly portable
as yet, but seems to work plausibly on Linux.

[originally from svn r2058]
2002-10-15 12:29:52 +00:00
Simon Tatham
cec0515b2c Support for BSD-style pty devices. Tested under Linux; might need
minor tweaks to run under other BSD-style OSes.

[originally from svn r2056]
2002-10-15 10:49:38 +00:00