mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 09:27:59 +00:00
f00c72cc2a
All this Interactor business has been gradually working towards being able to inform the user _which_ network connection is currently presenting them with a password prompt (or whatever), in situations where more than one of them might be, such as an SSH connection being used as a proxy for another SSH connection when neither one has one-touch login configured. At some point, we have to arrange that any attempt to do a user interaction during connection setup - be it a password prompt, a host key confirmation dialog, or just displaying an SSH login banner - makes it clear which host it's come from. That's going to mean calling some kind of announcement function before doing any of those things. But there are several of those functions in the Seat API, and calls to them are scattered far and wide across the SSH backend. (And not even just there - the Rlogin backend also uses seat_get_userpass_input). How can we possibly make sure we don't forget a vital call site on some obscure little-tested code path, and leave the user confused in just that one case which nobody might notice for years? Today I thought of a trick to solve that problem. We can use the C type system to enforce it for us! The plan is: we invent a new struct type which contains nothing but a 'Seat *'. Then, for every Seat method which does a thing that ought to be clearly identified as relating to a particular Interactor, we adjust the API for that function to take the new struct type where it previously took a plain 'Seat *'. Or rather - doing less violence to the existing code - we only need to adjust the API of the dispatch functions inline in putty.h. How does that help? Because the way you _get_ one of these struct-wrapped Seat pointers is by calling interactor_announce() on your Interactor, which will in turn call interactor_get_seat(), and wrap the returned pointer into one of these structs. The effect is that whenever the SSH (or Rlogin) code wants to call one of those particular Seat methods, it _has_ to call interactor_announce() just beforehand, which (once I finish all of this) will make sure the user is aware of who is presenting the prompt or banner or whatever. And you can't forget to call it, because if you don't call it, then you just don't have a struct of the right type to give to the Seat method you wanted to call! (Of course, there's nothing stopping code from _deliberately_ taking a Seat * it already has and wrapping it into the new struct. In fact SshProxy has to do that, in order to forward these requests up the chain of Seats. But the point is that you can't do it _by accident_, just by forgetting to make a vital function call - when you do that, you _know_ you're doing it on purpose.) No functional change: the new interactor_announce() function exists, and the type-system trick ensures it's called in all the right places, but it doesn't actually _do_ anything yet.
214 lines
6.6 KiB
C
214 lines
6.6 KiB
C
/*
|
|
* defs.h: initial definitions for PuTTY.
|
|
*
|
|
* The rule about this header file is that it can't depend on any
|
|
* other header file in this code base. This is where we define
|
|
* things, as much as we can, that other headers will want to refer
|
|
* to, such as opaque structure types and their associated typedefs,
|
|
* or macros that are used by other headers.
|
|
*/
|
|
|
|
#ifndef PUTTY_DEFS_H
|
|
#define PUTTY_DEFS_H
|
|
|
|
#ifdef NDEBUG
|
|
/*
|
|
* PuTTY is a security project, so assertions are important - if an
|
|
* assumption is violated, proceeding anyway may have far worse
|
|
* consequences than simple program termination. This check and #error
|
|
* should arrange that we don't ever accidentally compile assertions
|
|
* out.
|
|
*/
|
|
#error Do not compile this code base with NDEBUG defined!
|
|
#endif
|
|
|
|
#if HAVE_CMAKE_H
|
|
#include "cmake.h"
|
|
#endif
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h> /* for __MINGW_PRINTF_FORMAT */
|
|
#include <stdbool.h>
|
|
|
|
#if defined _MSC_VER && _MSC_VER < 1800
|
|
/* Work around lack of inttypes.h and strtoumax in older MSVC */
|
|
#define PRIx32 "x"
|
|
#define PRIu32 "u"
|
|
#define PRIu64 "I64u"
|
|
#define PRIdMAX "I64d"
|
|
#define PRIXMAX "I64X"
|
|
#define SCNu64 "I64u"
|
|
#define SIZEx "Ix"
|
|
#define SIZEu "Iu"
|
|
uintmax_t strtoumax(const char *nptr, char **endptr, int base);
|
|
#else
|
|
#include <inttypes.h>
|
|
/* Because we still support older MSVC libraries which don't recognise the
|
|
* standard C "z" modifier for size_t-sized integers, we must use an
|
|
* inttypes.h-style macro for those */
|
|
#define SIZEx "zx"
|
|
#define SIZEu "zu"
|
|
#endif
|
|
|
|
#if defined __GNUC__ || defined __clang__
|
|
/*
|
|
* On MinGW, the correct compiler format checking for vsnprintf() etc
|
|
* can depend on compile-time flags; these control whether you get
|
|
* ISO C or Microsoft's non-standard format strings.
|
|
* We sometimes use __attribute__ ((format)) for our own printf-like
|
|
* functions, which are ultimately interpreted by the toolchain-chosen
|
|
* printf, so we need to take that into account to get correct warnings.
|
|
*/
|
|
#ifdef __MINGW_PRINTF_FORMAT
|
|
#define PRINTF_LIKE(fmt_index, ellipsis_index) \
|
|
__attribute__ ((format (__MINGW_PRINTF_FORMAT, fmt_index, ellipsis_index)))
|
|
#else
|
|
#define PRINTF_LIKE(fmt_index, ellipsis_index) \
|
|
__attribute__ ((format (printf, fmt_index, ellipsis_index)))
|
|
#endif
|
|
#else /* __GNUC__ */
|
|
#define PRINTF_LIKE(fmt_index, ellipsis_index)
|
|
#endif /* __GNUC__ */
|
|
|
|
typedef struct conf_tag Conf;
|
|
typedef struct terminal_tag Terminal;
|
|
typedef struct term_utf8_decode term_utf8_decode;
|
|
|
|
typedef struct Filename Filename;
|
|
typedef struct FontSpec FontSpec;
|
|
|
|
typedef struct bufchain_tag bufchain;
|
|
|
|
typedef struct strbuf strbuf;
|
|
typedef struct LoadedFile LoadedFile;
|
|
|
|
typedef struct RSAKey RSAKey;
|
|
|
|
typedef struct BinarySink BinarySink;
|
|
typedef struct BinarySource BinarySource;
|
|
typedef struct stdio_sink stdio_sink;
|
|
typedef struct bufchain_sink bufchain_sink;
|
|
typedef struct handle_sink handle_sink;
|
|
|
|
typedef struct IdempotentCallback IdempotentCallback;
|
|
|
|
typedef struct SockAddr SockAddr;
|
|
|
|
typedef struct Socket Socket;
|
|
typedef struct Plug Plug;
|
|
typedef struct SocketPeerInfo SocketPeerInfo;
|
|
|
|
typedef struct Backend Backend;
|
|
typedef struct BackendVtable BackendVtable;
|
|
typedef struct Interactor Interactor;
|
|
typedef struct InteractorVtable InteractorVtable;
|
|
typedef struct InteractionReadySeat InteractionReadySeat;
|
|
|
|
typedef struct Ldisc_tag Ldisc;
|
|
typedef struct LogContext LogContext;
|
|
typedef struct LogPolicy LogPolicy;
|
|
typedef struct LogPolicyVtable LogPolicyVtable;
|
|
|
|
typedef struct Seat Seat;
|
|
typedef struct SeatVtable SeatVtable;
|
|
|
|
typedef struct TermWin TermWin;
|
|
typedef struct TermWinVtable TermWinVtable;
|
|
|
|
typedef struct Ssh Ssh;
|
|
|
|
typedef struct mp_int mp_int;
|
|
typedef struct MontyContext MontyContext;
|
|
|
|
typedef struct WeierstrassCurve WeierstrassCurve;
|
|
typedef struct WeierstrassPoint WeierstrassPoint;
|
|
typedef struct MontgomeryCurve MontgomeryCurve;
|
|
typedef struct MontgomeryPoint MontgomeryPoint;
|
|
typedef struct EdwardsCurve EdwardsCurve;
|
|
typedef struct EdwardsPoint EdwardsPoint;
|
|
|
|
typedef struct SshServerConfig SshServerConfig;
|
|
typedef struct SftpServer SftpServer;
|
|
typedef struct SftpServerVtable SftpServerVtable;
|
|
|
|
typedef struct Channel Channel;
|
|
typedef struct SshChannel SshChannel;
|
|
typedef struct mainchan mainchan;
|
|
|
|
typedef struct ssh_sharing_state ssh_sharing_state;
|
|
typedef struct ssh_sharing_connstate ssh_sharing_connstate;
|
|
typedef struct share_channel share_channel;
|
|
|
|
typedef struct PortFwdManager PortFwdManager;
|
|
typedef struct PortFwdRecord PortFwdRecord;
|
|
typedef struct ConnectionLayer ConnectionLayer;
|
|
|
|
typedef struct prng prng;
|
|
typedef struct ssh_hashalg ssh_hashalg;
|
|
typedef struct ssh_hash ssh_hash;
|
|
typedef struct ssh_kex ssh_kex;
|
|
typedef struct ssh_kexes ssh_kexes;
|
|
typedef struct ssh_keyalg ssh_keyalg;
|
|
typedef struct ssh_key ssh_key;
|
|
typedef struct ssh_compressor ssh_compressor;
|
|
typedef struct ssh_decompressor ssh_decompressor;
|
|
typedef struct ssh_compression_alg ssh_compression_alg;
|
|
typedef struct ssh2_userkey ssh2_userkey;
|
|
typedef struct ssh2_macalg ssh2_macalg;
|
|
typedef struct ssh2_mac ssh2_mac;
|
|
typedef struct ssh_cipheralg ssh_cipheralg;
|
|
typedef struct ssh_cipher ssh_cipher;
|
|
typedef struct ssh2_ciphers ssh2_ciphers;
|
|
typedef struct dh_ctx dh_ctx;
|
|
typedef struct ecdh_key ecdh_key;
|
|
|
|
typedef struct dlgparam dlgparam;
|
|
|
|
typedef struct settings_w settings_w;
|
|
typedef struct settings_r settings_r;
|
|
typedef struct settings_e settings_e;
|
|
|
|
typedef struct SessionSpecial SessionSpecial;
|
|
|
|
typedef struct StripCtrlChars StripCtrlChars;
|
|
|
|
typedef struct BidiContext BidiContext;
|
|
|
|
/*
|
|
* A small structure wrapping up a (pointer, length) pair so that it
|
|
* can be conveniently passed to or from a function.
|
|
*/
|
|
typedef struct ptrlen {
|
|
const void *ptr;
|
|
size_t len;
|
|
} ptrlen;
|
|
|
|
typedef struct logblank_t logblank_t;
|
|
|
|
typedef struct BinaryPacketProtocol BinaryPacketProtocol;
|
|
typedef struct PacketProtocolLayer PacketProtocolLayer;
|
|
|
|
/* Do a compile-time type-check of 'to_check' (without evaluating it),
|
|
* as a side effect of returning the value 'to_return'. Note that
|
|
* although this macro double-*expands* to_return, it always
|
|
* *evaluates* exactly one copy of it, so it's side-effect safe. */
|
|
#define TYPECHECK(to_check, to_return) \
|
|
(sizeof(to_check) ? (to_return) : (to_return))
|
|
|
|
/* Return a pointer to the object of structure type 'type' whose field
|
|
* with name 'field' is pointed at by 'object'. */
|
|
#define container_of(object, type, field) \
|
|
TYPECHECK(object == &((type *)0)->field, \
|
|
((type *)(((char *)(object)) - offsetof(type, field))))
|
|
|
|
#if defined __GNUC__ || defined __clang__
|
|
#define NORETURN __attribute__((__noreturn__))
|
|
#elif defined _MSC_VER
|
|
#define NORETURN __declspec(noreturn)
|
|
#else
|
|
#define NORETURN
|
|
#endif
|
|
|
|
#endif /* PUTTY_DEFS_H */
|