putty.h 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286
  1. #ifndef PUTTY_PUTTY_H
  2. #define PUTTY_PUTTY_H
  3. #include <stddef.h> /* for wchar_t */
  4. #include <limits.h> /* for INT_MAX */
  5. /*
  6. * Global variables. Most modules declare these `extern', but
  7. * window.c will do `#define PUTTY_DO_GLOBALS' before including this
  8. * module, and so will get them properly defined.
  9. */
  10. #ifndef GLOBAL
  11. #ifdef PUTTY_DO_GLOBALS
  12. #define GLOBAL
  13. #else
  14. #define GLOBAL extern
  15. #endif
  16. #endif
  17. #include "defs.h"
  18. #include "puttyps.h"
  19. #include "network.h"
  20. #include "misc.h"
  21. #include "marshal.h"
  22. /*
  23. * We express various time intervals in unsigned long minutes, but may need to
  24. * clip some values so that the resulting number of ticks does not overflow an
  25. * integer value.
  26. */
  27. #define MAX_TICK_MINS (INT_MAX / (60 * TICKSPERSEC))
  28. /*
  29. * Fingerprints of the current and previous PGP master keys, to
  30. * establish a trust path between an executable and other files.
  31. */
  32. #define PGP_MASTER_KEY_YEAR "2018"
  33. #define PGP_MASTER_KEY_DETAILS "RSA, 4096-bit"
  34. #define PGP_MASTER_KEY_FP \
  35. "24E1 B1C5 75EA 3C9F F752 A922 76BC 7FE4 EBFD 2D9E"
  36. #define PGP_PREV_MASTER_KEY_YEAR "2015"
  37. #define PGP_PREV_MASTER_KEY_DETAILS "RSA, 4096-bit"
  38. #define PGP_PREV_MASTER_KEY_FP \
  39. "440D E3B5 B7A1 CA85 B3CC 1718 AB58 5DC6 0467 6F7C"
  40. /* Three attribute types:
  41. * The ATTRs (normal attributes) are stored with the characters in
  42. * the main display arrays
  43. *
  44. * The TATTRs (temporary attributes) are generated on the fly, they
  45. * can overlap with characters but not with normal attributes.
  46. *
  47. * The LATTRs (line attributes) are an entirely disjoint space of
  48. * flags.
  49. *
  50. * The DATTRs (display attributes) are internal to terminal.c (but
  51. * defined here because their values have to match the others
  52. * here); they reuse the TATTR_* space but are always masked off
  53. * before sending to the front end.
  54. *
  55. * ATTR_INVALID is an illegal colour combination.
  56. */
  57. #define TATTR_ACTCURS 0x40000000UL /* active cursor (block) */
  58. #define TATTR_PASCURS 0x20000000UL /* passive cursor (box) */
  59. #define TATTR_RIGHTCURS 0x10000000UL /* cursor-on-RHS */
  60. #define TATTR_COMBINING 0x80000000UL /* combining characters */
  61. #define DATTR_STARTRUN 0x80000000UL /* start of redraw run */
  62. #define TDATTR_MASK 0xF0000000UL
  63. #define TATTR_MASK (TDATTR_MASK)
  64. #define DATTR_MASK (TDATTR_MASK)
  65. #define LATTR_NORM 0x00000000UL
  66. #define LATTR_WIDE 0x00000001UL
  67. #define LATTR_TOP 0x00000002UL
  68. #define LATTR_BOT 0x00000003UL
  69. #define LATTR_MODE 0x00000003UL
  70. #define LATTR_WRAPPED 0x00000010UL /* this line wraps to next */
  71. #define LATTR_WRAPPED2 0x00000020UL /* with WRAPPED: CJK wide character
  72. wrapped to next line, so last
  73. single-width cell is empty */
  74. #define ATTR_INVALID 0x03FFFFU
  75. /* Like Linux use the F000 page for direct to font. */
  76. #define CSET_OEMCP 0x0000F000UL /* OEM Codepage DTF */
  77. #define CSET_ACP 0x0000F100UL /* Ansi Codepage DTF */
  78. /* These are internal use overlapping with the UTF-16 surrogates */
  79. #define CSET_ASCII 0x0000D800UL /* normal ASCII charset ESC ( B */
  80. #define CSET_LINEDRW 0x0000D900UL /* line drawing charset ESC ( 0 */
  81. #define CSET_SCOACS 0x0000DA00UL /* SCO Alternate charset */
  82. #define CSET_GBCHR 0x0000DB00UL /* UK variant charset ESC ( A */
  83. #define CSET_MASK 0xFFFFFF00UL /* Character set mask */
  84. #define DIRECT_CHAR(c) ((c&0xFFFFFC00)==0xD800)
  85. #define DIRECT_FONT(c) ((c&0xFFFFFE00)==0xF000)
  86. #define UCSERR (CSET_LINEDRW|'a') /* UCS Format error character. */
  87. /*
  88. * UCSWIDE is a special value used in the terminal data to signify
  89. * the character cell containing the right-hand half of a CJK wide
  90. * character. We use 0xDFFF because it's part of the surrogate
  91. * range and hence won't be used for anything else (it's impossible
  92. * to input it via UTF-8 because our UTF-8 decoder correctly
  93. * rejects surrogates).
  94. */
  95. #define UCSWIDE 0xDFFF
  96. #define ATTR_NARROW 0x0800000U
  97. #define ATTR_WIDE 0x0400000U
  98. #define ATTR_BOLD 0x0040000U
  99. #define ATTR_UNDER 0x0080000U
  100. #define ATTR_REVERSE 0x0100000U
  101. #define ATTR_BLINK 0x0200000U
  102. #define ATTR_FGMASK 0x00001FFU
  103. #define ATTR_BGMASK 0x003FE00U
  104. #define ATTR_COLOURS 0x003FFFFU
  105. #define ATTR_DIM 0x1000000U
  106. #define ATTR_FGSHIFT 0
  107. #define ATTR_BGSHIFT 9
  108. /*
  109. * The definitive list of colour numbers stored in terminal
  110. * attribute words is kept here. It is:
  111. *
  112. * - 0-7 are ANSI colours (KRGYBMCW).
  113. * - 8-15 are the bold versions of those colours.
  114. * - 16-255 are the remains of the xterm 256-colour mode (a
  115. * 216-colour cube with R at most significant and B at least,
  116. * followed by a uniform series of grey shades running between
  117. * black and white but not including either on grounds of
  118. * redundancy).
  119. * - 256 is default foreground
  120. * - 257 is default bold foreground
  121. * - 258 is default background
  122. * - 259 is default bold background
  123. * - 260 is cursor foreground
  124. * - 261 is cursor background
  125. */
  126. #define ATTR_DEFFG (256 << ATTR_FGSHIFT)
  127. #define ATTR_DEFBG (258 << ATTR_BGSHIFT)
  128. #define ATTR_DEFAULT (ATTR_DEFFG | ATTR_DEFBG)
  129. struct sesslist {
  130. int nsessions;
  131. const char **sessions;
  132. char *buffer; /* so memory can be freed later */
  133. };
  134. struct unicode_data {
  135. char **uni_tbl;
  136. bool dbcs_screenfont;
  137. int font_codepage;
  138. int line_codepage;
  139. wchar_t unitab_scoacs[256];
  140. wchar_t unitab_line[256];
  141. wchar_t unitab_font[256];
  142. wchar_t unitab_xterm[256];
  143. wchar_t unitab_oemcp[256];
  144. unsigned char unitab_ctrl[256];
  145. };
  146. #define LGXF_OVR 1 /* existing logfile overwrite */
  147. #define LGXF_APN 0 /* existing logfile append */
  148. #define LGXF_ASK -1 /* existing logfile ask */
  149. #define LGTYP_NONE 0 /* logmode: no logging */
  150. #define LGTYP_ASCII 1 /* logmode: pure ascii */
  151. #define LGTYP_DEBUG 2 /* logmode: all chars of traffic */
  152. #define LGTYP_PACKETS 3 /* logmode: SSH data packets */
  153. #define LGTYP_SSHRAW 4 /* logmode: SSH raw data */
  154. /*
  155. * Enumeration of 'special commands' that can be sent during a
  156. * session, separately from the byte stream of ordinary session data.
  157. */
  158. typedef enum {
  159. /*
  160. * Commands that are generally useful in multiple backends.
  161. */
  162. SS_BRK, /* serial-line break */
  163. SS_EOF, /* end-of-file on session input */
  164. SS_NOP, /* transmit data with no effect */
  165. SS_PING, /* try to keep the session alive (probably, but not
  166. * necessarily, implemented as SS_NOP) */
  167. /*
  168. * Commands specific to Telnet.
  169. */
  170. SS_AYT, /* Are You There */
  171. SS_SYNCH, /* Synch */
  172. SS_EC, /* Erase Character */
  173. SS_EL, /* Erase Line */
  174. SS_GA, /* Go Ahead */
  175. SS_ABORT, /* Abort Process */
  176. SS_AO, /* Abort Output */
  177. SS_IP, /* Interrupt Process */
  178. SS_SUSP, /* Suspend Process */
  179. SS_EOR, /* End Of Record */
  180. SS_EOL, /* Telnet end-of-line sequence (CRLF, as opposed to CR
  181. * NUL that escapes a literal CR) */
  182. /*
  183. * Commands specific to SSH.
  184. */
  185. SS_REKEY, /* trigger an immediate repeat key exchange */
  186. SS_XCERT, /* cross-certify another host key ('arg' indicates which) */
  187. /*
  188. * Send a POSIX-style signal. (Useful in SSH and also pterm.)
  189. *
  190. * We use the master list in sshsignals.h to define these enum
  191. * values, which will come out looking like names of the form
  192. * SS_SIGABRT, SS_SIGINT etc.
  193. */
  194. #define SIGNAL_MAIN(name, text) SS_SIG ## name,
  195. #define SIGNAL_SUB(name) SS_SIG ## name,
  196. #include "sshsignals.h"
  197. #undef SIGNAL_MAIN
  198. #undef SIGNAL_SUB
  199. /*
  200. * These aren't really special commands, but they appear in the
  201. * enumeration because the list returned from
  202. * backend_get_specials() will use them to specify the structure
  203. * of the GUI specials menu.
  204. */
  205. SS_SEP, /* Separator */
  206. SS_SUBMENU, /* Start a new submenu with specified name */
  207. SS_EXITMENU, /* Exit current submenu, or end of entire specials list */
  208. } SessionSpecialCode;
  209. /*
  210. * The structure type returned from backend_get_specials.
  211. */
  212. struct SessionSpecial {
  213. const char *name;
  214. SessionSpecialCode code;
  215. int arg;
  216. };
  217. /* Needed by both sshchan.h and sshppl.h */
  218. typedef void (*add_special_fn_t)(
  219. void *ctx, const char *text, SessionSpecialCode code, int arg);
  220. typedef enum {
  221. MBT_NOTHING,
  222. MBT_LEFT, MBT_MIDDLE, MBT_RIGHT, /* `raw' button designations */
  223. MBT_SELECT, MBT_EXTEND, MBT_PASTE, /* `cooked' button designations */
  224. MBT_WHEEL_UP, MBT_WHEEL_DOWN /* mouse wheel */
  225. } Mouse_Button;
  226. typedef enum {
  227. MA_NOTHING, MA_CLICK, MA_2CLK, MA_3CLK, MA_DRAG, MA_RELEASE
  228. } Mouse_Action;
  229. /* Keyboard modifiers -- keys the user is actually holding down */
  230. #define PKM_SHIFT 0x01
  231. #define PKM_CONTROL 0x02
  232. #define PKM_META 0x04
  233. #define PKM_ALT 0x08
  234. /* Keyboard flags that aren't really modifiers */
  235. #define PKF_CAPSLOCK 0x10
  236. #define PKF_NUMLOCK 0x20
  237. #define PKF_REPEAT 0x40
  238. /* Stand-alone keysyms for function keys */
  239. typedef enum {
  240. PK_NULL, /* No symbol for this key */
  241. /* Main keypad keys */
  242. PK_ESCAPE, PK_TAB, PK_BACKSPACE, PK_RETURN, PK_COMPOSE,
  243. /* Editing keys */
  244. PK_HOME, PK_INSERT, PK_DELETE, PK_END, PK_PAGEUP, PK_PAGEDOWN,
  245. /* Cursor keys */
  246. PK_UP, PK_DOWN, PK_RIGHT, PK_LEFT, PK_REST,
  247. /* Numeric keypad */ /* Real one looks like: */
  248. PK_PF1, PK_PF2, PK_PF3, PK_PF4, /* PF1 PF2 PF3 PF4 */
  249. PK_KPCOMMA, PK_KPMINUS, PK_KPDECIMAL, /* 7 8 9 - */
  250. PK_KP0, PK_KP1, PK_KP2, PK_KP3, PK_KP4, /* 4 5 6 , */
  251. PK_KP5, PK_KP6, PK_KP7, PK_KP8, PK_KP9, /* 1 2 3 en- */
  252. PK_KPBIGPLUS, PK_KPENTER, /* 0 . ter */
  253. /* Top row */
  254. PK_F1, PK_F2, PK_F3, PK_F4, PK_F5,
  255. PK_F6, PK_F7, PK_F8, PK_F9, PK_F10,
  256. PK_F11, PK_F12, PK_F13, PK_F14, PK_F15,
  257. PK_F16, PK_F17, PK_F18, PK_F19, PK_F20,
  258. PK_PAUSE
  259. } Key_Sym;
  260. #define PK_ISEDITING(k) ((k) >= PK_HOME && (k) <= PK_PAGEDOWN)
  261. #define PK_ISCURSOR(k) ((k) >= PK_UP && (k) <= PK_REST)
  262. #define PK_ISKEYPAD(k) ((k) >= PK_PF1 && (k) <= PK_KPENTER)
  263. #define PK_ISFKEY(k) ((k) >= PK_F1 && (k) <= PK_F20)
  264. enum {
  265. VT_XWINDOWS, VT_OEMANSI, VT_OEMONLY, VT_POORMAN, VT_UNICODE
  266. };
  267. enum {
  268. /*
  269. * SSH-2 key exchange algorithms
  270. */
  271. KEX_WARN,
  272. KEX_DHGROUP1,
  273. KEX_DHGROUP14,
  274. KEX_DHGEX,
  275. KEX_RSA,
  276. KEX_ECDH,
  277. KEX_MAX
  278. };
  279. enum {
  280. /*
  281. * SSH-2 host key algorithms
  282. */
  283. HK_WARN,
  284. HK_RSA,
  285. HK_DSA,
  286. HK_ECDSA,
  287. HK_ED25519,
  288. HK_MAX
  289. };
  290. enum {
  291. /*
  292. * SSH ciphers (both SSH-1 and SSH-2)
  293. */
  294. CIPHER_WARN, /* pseudo 'cipher' */
  295. CIPHER_3DES,
  296. CIPHER_BLOWFISH,
  297. CIPHER_AES, /* (SSH-2 only) */
  298. CIPHER_DES,
  299. CIPHER_ARCFOUR,
  300. CIPHER_CHACHA20,
  301. CIPHER_MAX /* no. ciphers (inc warn) */
  302. };
  303. enum TriState {
  304. /*
  305. * Several different bits of the PuTTY configuration seem to be
  306. * three-way settings whose values are `always yes', `always
  307. * no', and `decide by some more complex automated means'. This
  308. * is true of line discipline options (local echo and line
  309. * editing), proxy DNS, proxy terminal logging, Close On Exit, and
  310. * SSH server bug workarounds. Accordingly I supply a single enum
  311. * here to deal with them all.
  312. */
  313. FORCE_ON, FORCE_OFF, AUTO
  314. };
  315. enum {
  316. /*
  317. * Proxy types.
  318. */
  319. PROXY_NONE, PROXY_SOCKS4, PROXY_SOCKS5,
  320. PROXY_HTTP, PROXY_TELNET, PROXY_CMD, PROXY_FUZZ
  321. };
  322. enum {
  323. /*
  324. * Line discipline options which the backend might try to control.
  325. */
  326. LD_EDIT, /* local line editing */
  327. LD_ECHO, /* local echo */
  328. LD_N_OPTIONS
  329. };
  330. enum {
  331. /* Actions on remote window title query */
  332. TITLE_NONE, TITLE_EMPTY, TITLE_REAL
  333. };
  334. enum {
  335. /* Protocol back ends. (CONF_protocol) */
  336. PROT_RAW, PROT_TELNET, PROT_RLOGIN, PROT_SSH,
  337. /* PROT_SERIAL is supported on a subset of platforms, but it doesn't
  338. * hurt to define it globally. */
  339. PROT_SERIAL
  340. };
  341. enum {
  342. /* Bell settings (CONF_beep) */
  343. BELL_DISABLED, BELL_DEFAULT, BELL_VISUAL, BELL_WAVEFILE, BELL_PCSPEAKER
  344. };
  345. enum {
  346. /* Taskbar flashing indication on bell (CONF_beep_ind) */
  347. B_IND_DISABLED, B_IND_FLASH, B_IND_STEADY
  348. };
  349. enum {
  350. /* Resize actions (CONF_resize_action) */
  351. RESIZE_TERM, RESIZE_DISABLED, RESIZE_FONT, RESIZE_EITHER
  352. };
  353. enum {
  354. /* Function key types (CONF_funky_type) */
  355. FUNKY_TILDE,
  356. FUNKY_LINUX,
  357. FUNKY_XTERM,
  358. FUNKY_VT400,
  359. FUNKY_VT100P,
  360. FUNKY_SCO
  361. };
  362. enum {
  363. FQ_DEFAULT, FQ_ANTIALIASED, FQ_NONANTIALIASED, FQ_CLEARTYPE
  364. };
  365. enum {
  366. SER_PAR_NONE, SER_PAR_ODD, SER_PAR_EVEN, SER_PAR_MARK, SER_PAR_SPACE
  367. };
  368. enum {
  369. SER_FLOW_NONE, SER_FLOW_XONXOFF, SER_FLOW_RTSCTS, SER_FLOW_DSRDTR
  370. };
  371. /*
  372. * Tables of string <-> enum value mappings used in settings.c.
  373. * Defined here so that backends can export their GSS library tables
  374. * to the cross-platform settings code.
  375. */
  376. struct keyvalwhere {
  377. /*
  378. * Two fields which define a string and enum value to be
  379. * equivalent to each other.
  380. */
  381. const char *s;
  382. int v;
  383. /*
  384. * The next pair of fields are used by gprefs() in settings.c to
  385. * arrange that when it reads a list of strings representing a
  386. * preference list and translates it into the corresponding list
  387. * of integers, strings not appearing in the list are entered in a
  388. * configurable position rather than uniformly at the end.
  389. */
  390. /*
  391. * 'vrel' indicates which other value in the list to place this
  392. * element relative to. It should be a value that has occurred in
  393. * a 'v' field of some other element of the array, or -1 to
  394. * indicate that we simply place relative to one or other end of
  395. * the list.
  396. *
  397. * gprefs will try to process the elements in an order which makes
  398. * this field work (i.e. so that the element referenced has been
  399. * added before processing this one).
  400. */
  401. int vrel;
  402. /*
  403. * 'where' indicates whether to place the new value before or
  404. * after the one referred to by vrel. -1 means before; +1 means
  405. * after.
  406. *
  407. * When vrel is -1, this also implicitly indicates which end of
  408. * the array to use. So vrel=-1, where=-1 means to place _before_
  409. * some end of the list (hence, at the last element); vrel=-1,
  410. * where=+1 means to place _after_ an end (hence, at the first).
  411. */
  412. int where;
  413. };
  414. #ifndef NO_GSSAPI
  415. extern const int ngsslibs;
  416. extern const char *const gsslibnames[]; /* for displaying in configuration */
  417. extern const struct keyvalwhere gsslibkeywords[]; /* for settings.c */
  418. #endif
  419. extern const char *const ttymodes[];
  420. enum {
  421. /*
  422. * Network address types. Used for specifying choice of IPv4/v6
  423. * in config; also used in proxy.c to indicate whether a given
  424. * host name has already been resolved or will be resolved at
  425. * the proxy end.
  426. */
  427. ADDRTYPE_UNSPEC,
  428. ADDRTYPE_IPV4,
  429. ADDRTYPE_IPV6,
  430. ADDRTYPE_LOCAL, /* e.g. Unix domain socket, or Windows named pipe */
  431. ADDRTYPE_NAME /* SockAddr storing an unresolved host name */
  432. };
  433. struct Backend {
  434. const BackendVtable *vt;
  435. };
  436. struct BackendVtable {
  437. const char *(*init) (Seat *seat, Backend **backend_out,
  438. LogContext *logctx, Conf *conf,
  439. const char *host, int port,
  440. char **realhost, bool nodelay, bool keepalive);
  441. void (*free) (Backend *be);
  442. /* Pass in a replacement configuration. */
  443. void (*reconfig) (Backend *be, Conf *conf);
  444. /* send() returns the current amount of buffered data. */
  445. size_t (*send) (Backend *be, const char *buf, size_t len);
  446. /* sendbuffer() does the same thing but without attempting a send */
  447. size_t (*sendbuffer) (Backend *be);
  448. void (*size) (Backend *be, int width, int height);
  449. void (*special) (Backend *be, SessionSpecialCode code, int arg);
  450. const SessionSpecial *(*get_specials) (Backend *be);
  451. bool (*connected) (Backend *be);
  452. int (*exitcode) (Backend *be);
  453. /* If back->sendok() returns false, the backend doesn't currently
  454. * want input data, so the frontend should avoid acquiring any if
  455. * possible (passing back-pressure on to its sender). */
  456. bool (*sendok) (Backend *be);
  457. bool (*ldisc_option_state) (Backend *be, int);
  458. void (*provide_ldisc) (Backend *be, Ldisc *ldisc);
  459. /* Tells the back end that the front end buffer is clearing. */
  460. void (*unthrottle) (Backend *be, size_t bufsize);
  461. int (*cfg_info) (Backend *be);
  462. /* Only implemented in the SSH protocol: check whether a
  463. * connection-sharing upstream exists for a given configuration. */
  464. bool (*test_for_upstream)(const char *host, int port, Conf *conf);
  465. const char *name;
  466. int protocol;
  467. int default_port;
  468. };
  469. static inline const char *backend_init(
  470. const BackendVtable *vt, Seat *seat, Backend **out, LogContext *logctx,
  471. Conf *conf, const char *host, int port, char **rhost, bool nd, bool ka)
  472. { return vt->init(seat, out, logctx, conf, host, port, rhost, nd, ka); }
  473. static inline void backend_free(Backend *be)
  474. { be->vt->free(be); }
  475. static inline void backend_reconfig(Backend *be, Conf *conf)
  476. { be->vt->reconfig(be, conf); }
  477. static inline size_t backend_send(Backend *be, const char *buf, size_t len)
  478. { return be->vt->send(be, buf, len); }
  479. static inline size_t backend_sendbuffer(Backend *be)
  480. { return be->vt->sendbuffer(be); }
  481. static inline void backend_size(Backend *be, int width, int height)
  482. { be->vt->size(be, width, height); }
  483. static inline void backend_special(
  484. Backend *be, SessionSpecialCode code, int arg)
  485. { be->vt->special(be, code, arg); }
  486. static inline const SessionSpecial *backend_get_specials(Backend *be)
  487. { return be->vt->get_specials(be); }
  488. static inline bool backend_connected(Backend *be)
  489. { return be->vt->connected(be); }
  490. static inline int backend_exitcode(Backend *be)
  491. { return be->vt->exitcode(be); }
  492. static inline bool backend_sendok(Backend *be)
  493. { return be->vt->sendok(be); }
  494. static inline bool backend_ldisc_option_state(Backend *be, int state)
  495. { return be->vt->ldisc_option_state(be, state); }
  496. static inline void backend_provide_ldisc(Backend *be, Ldisc *ldisc)
  497. { be->vt->provide_ldisc(be, ldisc); }
  498. static inline void backend_unthrottle(Backend *be, size_t bufsize)
  499. { be->vt->unthrottle(be, bufsize); }
  500. static inline int backend_cfg_info(Backend *be)
  501. { return be->vt->cfg_info(be); }
  502. extern const struct BackendVtable *const backends[];
  503. /*
  504. * Suggested default protocol provided by the backend link module.
  505. * The application is free to ignore this.
  506. */
  507. extern const int be_default_protocol;
  508. /*
  509. * Name of this particular application, for use in the config box
  510. * and other pieces of text.
  511. */
  512. extern const char *const appname;
  513. /*
  514. * Some global flags denoting the type of application.
  515. *
  516. * FLAG_VERBOSE is set when the user requests verbose details.
  517. *
  518. * FLAG_INTERACTIVE is set when a full interactive shell session is
  519. * being run, _either_ because no remote command has been provided
  520. * _or_ because the application is GUI and can't run non-
  521. * interactively.
  522. *
  523. * These flags describe the type of _application_ - they wouldn't
  524. * vary between individual sessions - and so it's OK to have this
  525. * variable be GLOBAL.
  526. *
  527. * Note that additional flags may be defined in platform-specific
  528. * headers. It's probably best if those ones start from 0x1000, to
  529. * avoid collision.
  530. */
  531. #define FLAG_VERBOSE 0x0001
  532. #define FLAG_INTERACTIVE 0x0002
  533. GLOBAL int flags;
  534. /*
  535. * Likewise, these two variables are set up when the application
  536. * initialises, and inform all default-settings accesses after
  537. * that.
  538. */
  539. GLOBAL int default_protocol;
  540. GLOBAL int default_port;
  541. /*
  542. * This is set true by cmdline.c iff a session is loaded with "-load".
  543. */
  544. GLOBAL bool loaded_session;
  545. /*
  546. * This is set to the name of the loaded session.
  547. */
  548. GLOBAL char *cmdline_session_name;
  549. /*
  550. * Mechanism for getting text strings such as usernames and passwords
  551. * from the front-end.
  552. * The fields are mostly modelled after SSH's keyboard-interactive auth.
  553. * FIXME We should probably mandate a character set/encoding (probably UTF-8).
  554. *
  555. * Since many of the pieces of text involved may be chosen by the server,
  556. * the caller must take care to ensure that the server can't spoof locally-
  557. * generated prompts such as key passphrase prompts. Some ground rules:
  558. * - If the front-end needs to truncate a string, it should lop off the
  559. * end.
  560. * - The front-end should filter out any dangerous characters and
  561. * generally not trust the strings. (But \n is required to behave
  562. * vaguely sensibly, at least in `instruction', and ideally in
  563. * `prompt[]' too.)
  564. */
  565. typedef struct {
  566. char *prompt;
  567. bool echo;
  568. /*
  569. * 'result' must be a dynamically allocated array of exactly
  570. * 'resultsize' chars. The code for actually reading input may
  571. * realloc it bigger (and adjust resultsize accordingly) if it has
  572. * to. The caller should free it again when finished with it.
  573. *
  574. * If resultsize==0, then result may be NULL. When setting up a
  575. * prompt_t, it's therefore easiest to initialise them this way,
  576. * which means all actual allocation is done by the callee. This
  577. * is what add_prompt does.
  578. */
  579. char *result;
  580. size_t resultsize;
  581. } prompt_t;
  582. typedef struct {
  583. /*
  584. * Indicates whether the information entered is to be used locally
  585. * (for instance a key passphrase prompt), or is destined for the wire.
  586. * This is a hint only; the front-end is at liberty not to use this
  587. * information (so the caller should ensure that the supplied text is
  588. * sufficient).
  589. */
  590. bool to_server;
  591. /*
  592. * Indicates whether the prompts originated _at_ the server, so
  593. * that the front end can display some kind of trust sigil that
  594. * distinguishes (say) a legit private-key passphrase prompt from
  595. * a fake one sent by a malicious server.
  596. */
  597. bool from_server;
  598. char *name; /* Short description, perhaps for dialog box title */
  599. bool name_reqd; /* Display of `name' required or optional? */
  600. char *instruction; /* Long description, maybe with embedded newlines */
  601. bool instr_reqd; /* Display of `instruction' required or optional? */
  602. size_t n_prompts; /* May be zero (in which case display the foregoing,
  603. * if any, and return success) */
  604. size_t prompts_size; /* allocated storage capacity for prompts[] */
  605. prompt_t **prompts;
  606. void *data; /* slot for housekeeping data, managed by
  607. * seat_get_userpass_input(); initially NULL */
  608. } prompts_t;
  609. prompts_t *new_prompts(void); // WINSCP (void)
  610. void add_prompt(prompts_t *p, char *promptstr, bool echo);
  611. void prompt_set_result(prompt_t *pr, const char *newstr);
  612. void prompt_ensure_result_size(prompt_t *pr, int len);
  613. /* Burn the evidence. (Assumes _all_ strings want free()ing.) */
  614. void free_prompts(prompts_t *p);
  615. /*
  616. * Data type definitions for true-colour terminal display.
  617. * 'optionalrgb' describes a single RGB colour, which overrides the
  618. * other colour settings if 'enabled' is nonzero, and is ignored
  619. * otherwise. 'truecolour' contains a pair of those for foreground and
  620. * background.
  621. */
  622. typedef struct optionalrgb {
  623. bool enabled;
  624. unsigned char r, g, b;
  625. } optionalrgb;
  626. extern const optionalrgb optionalrgb_none;
  627. typedef struct truecolour {
  628. optionalrgb fg, bg;
  629. } truecolour;
  630. #define optionalrgb_equal(r1,r2) ( \
  631. (r1).enabled==(r2).enabled && \
  632. (r1).r==(r2).r && (r1).g==(r2).g && (r1).b==(r2).b)
  633. #define truecolour_equal(c1,c2) ( \
  634. optionalrgb_equal((c1).fg, (c2).fg) && \
  635. optionalrgb_equal((c1).bg, (c2).bg))
  636. /*
  637. * Enumeration of clipboards. We provide some standard ones cross-
  638. * platform, and then permit each platform to extend this enumeration
  639. * further by defining PLATFORM_CLIPBOARDS in its own header file.
  640. *
  641. * CLIP_NULL is a non-clipboard, writes to which are ignored and reads
  642. * from which return no data.
  643. *
  644. * CLIP_LOCAL refers to a buffer within terminal.c, which
  645. * unconditionally saves the last data selected in the terminal. In
  646. * configurations where a system clipboard is not written
  647. * automatically on selection but instead by an explicit UI action,
  648. * this is where the code responding to that action can find the data
  649. * to write to the clipboard in question.
  650. */
  651. #define CROSS_PLATFORM_CLIPBOARDS(X) \
  652. X(CLIP_NULL, "null clipboard") \
  653. X(CLIP_LOCAL, "last text selected in terminal") \
  654. /* end of list */
  655. #define ALL_CLIPBOARDS(X) \
  656. CROSS_PLATFORM_CLIPBOARDS(X) \
  657. PLATFORM_CLIPBOARDS(X) \
  658. /* end of list */
  659. #define CLIP_ID(id,name) id,
  660. enum { ALL_CLIPBOARDS(CLIP_ID) N_CLIPBOARDS };
  661. #undef CLIP_ID
  662. /* Hint from backend to frontend about time-consuming operations, used
  663. * by seat_set_busy_status. Initial state is assumed to be
  664. * BUSY_NOT. */
  665. typedef enum BusyStatus {
  666. BUSY_NOT, /* Not busy, all user interaction OK */
  667. BUSY_WAITING, /* Waiting for something; local event loops still
  668. running so some local interaction (e.g. menus)
  669. OK, but network stuff is suspended */
  670. BUSY_CPU /* Locally busy (e.g. crypto); user interaction
  671. * suspended */
  672. } BusyStatus;
  673. typedef enum SeatInteractionContext {
  674. SIC_BANNER, SIC_KI_PROMPTS
  675. } SeatInteractionContext;
  676. /*
  677. * Data type 'Seat', which is an API intended to contain essentially
  678. * everything that a back end might need to talk to its client for:
  679. * session output, password prompts, SSH warnings about host keys and
  680. * weak cryptography, notifications of events like the remote process
  681. * exiting or the GUI specials menu needing an update.
  682. */
  683. struct Seat {
  684. const struct SeatVtable *vt;
  685. };
  686. struct SeatVtable {
  687. /*
  688. * Provide output from the remote session. 'is_stderr' indicates
  689. * that the output should be sent to a separate error message
  690. * channel, if the seat has one. But combining both channels into
  691. * one is OK too; that's what terminal-window based seats do.
  692. *
  693. * The return value is the current size of the output backlog.
  694. */
  695. size_t (*output)(Seat *seat, bool is_stderr, const void *data, size_t len);
  696. /*
  697. * Called when the back end wants to indicate that EOF has arrived
  698. * on the server-to-client stream. Returns false to indicate that
  699. * we intend to keep the session open in the other direction, or
  700. * true to indicate that if they're closing so are we.
  701. */
  702. bool (*eof)(Seat *seat);
  703. /*
  704. * Try to get answers from a set of interactive login prompts. The
  705. * prompts are provided in 'p'; the bufchain 'input' holds the
  706. * data currently outstanding in the session's normal standard-
  707. * input channel. Seats may implement this function by consuming
  708. * data from 'input' (e.g. password prompts in GUI PuTTY,
  709. * displayed in the same terminal as the subsequent session), or
  710. * by doing something entirely different (e.g. directly
  711. * interacting with standard I/O, or putting up a dialog box).
  712. *
  713. * A positive return value means that all prompts have had answers
  714. * filled in. A zero return means that the user performed a
  715. * deliberate 'cancel' UI action. A negative return means that no
  716. * answer can be given yet but please try again later.
  717. *
  718. * (FIXME: it would be nice to distinguish two classes of cancel
  719. * action, so the user could specify 'I want to abandon this
  720. * entire attempt to start a session' or the milder 'I want to
  721. * abandon this particular form of authentication and fall back to
  722. * a different one' - e.g. if you turn out not to be able to
  723. * remember your private key passphrase then perhaps you'd rather
  724. * fall back to password auth rather than aborting the whole
  725. * session.)
  726. *
  727. * (Also FIXME: currently, backends' only response to the 'try
  728. * again later' is to try again when more input data becomes
  729. * available, because they assume that a seat is returning that
  730. * value because it's consuming keyboard input. But a seat that
  731. * handled this function by putting up a dialog box might want to
  732. * put it up non-modally, and therefore would want to proactively
  733. * notify the backend to retry once the dialog went away. So if I
  734. * ever do want to move password prompts into a dialog box, I'll
  735. * want a backend method for sending that notification.)
  736. */
  737. int (*get_userpass_input)(Seat *seat, prompts_t *p, bufchain *input);
  738. /*
  739. * Notify the seat that the process running at the other end of
  740. * the connection has finished.
  741. */
  742. void (*notify_remote_exit)(Seat *seat);
  743. /*
  744. * Notify the seat that the connection has suffered a fatal error.
  745. */
  746. void (*connection_fatal)(Seat *seat, const char *message);
  747. /*
  748. * Notify the seat that the list of special commands available
  749. * from backend_get_specials() has changed, so that it might want
  750. * to call that function to repopulate its menu.
  751. *
  752. * Seats are not expected to call backend_get_specials()
  753. * proactively; they may start by assuming that the backend
  754. * provides no special commands at all, so if the backend does
  755. * provide any, then it should use this notification at startup
  756. * time. Of course it can also invoke it later if the set of
  757. * special commands changes.
  758. *
  759. * It does not need to invoke it at session shutdown.
  760. */
  761. void (*update_specials_menu)(Seat *seat);
  762. /*
  763. * Get the seat's preferred value for an SSH terminal mode
  764. * setting. Returning NULL indicates no preference (i.e. the SSH
  765. * connection will not attempt to set the mode at all).
  766. *
  767. * The returned value is dynamically allocated, and the caller
  768. * should free it.
  769. */
  770. char *(*get_ttymode)(Seat *seat, const char *mode);
  771. /*
  772. * Tell the seat whether the backend is currently doing anything
  773. * CPU-intensive (typically a cryptographic key exchange). See
  774. * BusyStatus enumeration above.
  775. */
  776. void (*set_busy_status)(Seat *seat, BusyStatus status);
  777. /*
  778. * Ask the seat whether a given SSH host key should be accepted.
  779. * This may return immediately after checking saved configuration
  780. * or command-line options, or it may have to present a prompt to
  781. * the user and return asynchronously later.
  782. *
  783. * Return values:
  784. *
  785. * - +1 means `key was OK' (either already known or the user just
  786. * approved it) `so continue with the connection'
  787. *
  788. * - 0 means `key was not OK, abandon the connection'
  789. *
  790. * - -1 means `I've initiated enquiries, please wait to be called
  791. * back via the provided function with a result that's either 0
  792. * or +1'.
  793. */
  794. int (*verify_ssh_host_key)(
  795. Seat *seat, const char *host, int port,
  796. const char *keytype, char *keystr, char *key_fingerprint,
  797. void (*callback)(void *ctx, int result), void *ctx);
  798. /*
  799. * Check with the seat whether it's OK to use a cryptographic
  800. * primitive from below the 'warn below this line' threshold in
  801. * the input Conf. Return values are the same as
  802. * verify_ssh_host_key above.
  803. */
  804. int (*confirm_weak_crypto_primitive)(
  805. Seat *seat, const char *algtype, const char *algname,
  806. void (*callback)(void *ctx, int result), void *ctx);
  807. /*
  808. * Variant form of confirm_weak_crypto_primitive, which prints a
  809. * slightly different message but otherwise has the same
  810. * semantics.
  811. *
  812. * This form is used in the case where we're using a host key
  813. * below the warning threshold because that's the best one we have
  814. * cached, but at least one host key algorithm *above* the
  815. * threshold is available that we don't have cached. 'betteralgs'
  816. * lists the better algorithm(s).
  817. */
  818. int (*confirm_weak_cached_hostkey)(
  819. Seat *seat, const char *algname, const char *betteralgs,
  820. void (*callback)(void *ctx, int result), void *ctx);
  821. /*
  822. * Indicates whether the seat is expecting to interact with the
  823. * user in the UTF-8 character set. (Affects e.g. visual erase
  824. * handling in local line editing.)
  825. */
  826. bool (*is_utf8)(Seat *seat);
  827. /*
  828. * Notify the seat that the back end, and/or the ldisc between
  829. * them, have changed their idea of whether they currently want
  830. * local echo and/or local line editing enabled.
  831. */
  832. void (*echoedit_update)(Seat *seat, bool echoing, bool editing);
  833. /*
  834. * Return the local X display string relevant to a seat, or NULL
  835. * if there isn't one or if the concept is meaningless.
  836. */
  837. const char *(*get_x_display)(Seat *seat);
  838. /*
  839. * Return the X11 id of the X terminal window relevant to a seat,
  840. * by returning true and filling in the output pointer. Return
  841. * false if there isn't one or if the concept is meaningless.
  842. */
  843. bool (*get_windowid)(Seat *seat, long *id_out);
  844. /*
  845. * Return the size of the terminal window in pixels. If the
  846. * concept is meaningless or the information is unavailable,
  847. * return false; otherwise fill in the output pointers and return
  848. * true.
  849. */
  850. bool (*get_window_pixel_size)(Seat *seat, int *width, int *height);
  851. /*
  852. * Return a StripCtrlChars appropriate for sanitising untrusted
  853. * terminal data (e.g. SSH banners, prompts) being sent to the
  854. * user of this seat. May return NULL if no sanitisation is
  855. * needed.
  856. */
  857. StripCtrlChars *(*stripctrl_new)(
  858. Seat *seat, BinarySink *bs_out, SeatInteractionContext sic);
  859. /*
  860. * Set the seat's current idea of where output is coming from.
  861. * True means that output is being generated by our own code base
  862. * (and hence, can be trusted if it's asking you for secrets such
  863. * as your passphrase); false means output is coming from the
  864. * server.
  865. *
  866. * Returns true if the seat has a way to indicate this
  867. * distinction. Returns false if not, in which case the backend
  868. * should use a fallback defence against spoofing of PuTTY's local
  869. * prompts by malicious servers.
  870. */
  871. bool (*set_trust_status)(Seat *seat, bool trusted);
  872. };
  873. static inline size_t seat_output(
  874. Seat *seat, bool err, const void *data, size_t len)
  875. { return seat->vt->output(seat, err, data, len); }
  876. static inline bool seat_eof(Seat *seat)
  877. { return seat->vt->eof(seat); }
  878. static inline int seat_get_userpass_input(
  879. Seat *seat, prompts_t *p, bufchain *input)
  880. { return seat->vt->get_userpass_input(seat, p, input); }
  881. static inline void seat_notify_remote_exit(Seat *seat)
  882. { seat->vt->notify_remote_exit(seat); }
  883. static inline void seat_update_specials_menu(Seat *seat)
  884. { seat->vt->update_specials_menu(seat); }
  885. static inline char *seat_get_ttymode(Seat *seat, const char *mode)
  886. { return seat->vt->get_ttymode(seat, mode); }
  887. static inline void seat_set_busy_status(Seat *seat, BusyStatus status)
  888. { seat->vt->set_busy_status(seat, status); }
  889. static inline int seat_verify_ssh_host_key(
  890. Seat *seat, const char *h, int p, const char *ktyp, char *kstr,
  891. char *fp, void (*cb)(void *ctx, int result), void *ctx)
  892. { return seat->vt->verify_ssh_host_key(seat, h, p, ktyp, kstr, fp, cb, ctx); }
  893. static inline int seat_confirm_weak_crypto_primitive(
  894. Seat *seat, const char *atyp, const char *aname,
  895. void (*cb)(void *ctx, int result), void *ctx)
  896. { return seat->vt->confirm_weak_crypto_primitive(seat, atyp, aname, cb, ctx); }
  897. static inline int seat_confirm_weak_cached_hostkey(
  898. Seat *seat, const char *aname, const char *better,
  899. void (*cb)(void *ctx, int result), void *ctx)
  900. { return seat->vt->confirm_weak_cached_hostkey(seat, aname, better, cb, ctx); }
  901. static inline bool seat_is_utf8(Seat *seat)
  902. { return seat->vt->is_utf8(seat); }
  903. static inline void seat_echoedit_update(Seat *seat, bool ec, bool ed)
  904. { seat->vt->echoedit_update(seat, ec, ed); }
  905. static inline const char *seat_get_x_display(Seat *seat)
  906. { return seat->vt->get_x_display(seat); }
  907. static inline bool seat_get_windowid(Seat *seat, long *id_out)
  908. { return seat->vt->get_windowid(seat, id_out); }
  909. static inline bool seat_get_window_pixel_size(Seat *seat, int *w, int *h)
  910. { return seat->vt->get_window_pixel_size(seat, w, h); }
  911. static inline StripCtrlChars *seat_stripctrl_new(
  912. Seat *seat, BinarySink *bs, SeatInteractionContext sic)
  913. { return seat->vt->stripctrl_new(seat, bs, sic); }
  914. static inline bool seat_set_trust_status(Seat *seat, bool trusted)
  915. { return seat->vt->set_trust_status(seat, trusted); }
  916. /* Unlike the seat's actual method, the public entry point
  917. * seat_connection_fatal is a wrapper function with a printf-like API,
  918. * defined in misc.c. */
  919. void seat_connection_fatal(Seat *seat, const char *fmt, ...);
  920. /* Handy aliases for seat_output which set is_stderr to a fixed value. */
  921. static inline size_t seat_stdout(Seat *seat, const void *data, size_t len)
  922. { return seat_output(seat, false, data, len); }
  923. static inline size_t seat_stdout_pl(Seat *seat, ptrlen data)
  924. { return seat_output(seat, false, data.ptr, data.len); }
  925. static inline size_t seat_stderr(Seat *seat, const void *data, size_t len)
  926. { return seat_output(seat, true, data, len); }
  927. static inline size_t seat_stderr_pl(Seat *seat, ptrlen data)
  928. { return seat_output(seat, true, data.ptr, data.len); }
  929. /*
  930. * Stub methods for seat implementations that want to use the obvious
  931. * null handling for a given method.
  932. *
  933. * These are generally obvious, except for is_utf8, where you might
  934. * plausibly want to return either fixed answer 'no' or 'yes'.
  935. */
  936. size_t nullseat_output(
  937. Seat *seat, bool is_stderr, const void *data, size_t len);
  938. bool nullseat_eof(Seat *seat);
  939. int nullseat_get_userpass_input(Seat *seat, prompts_t *p, bufchain *input);
  940. void nullseat_notify_remote_exit(Seat *seat);
  941. void nullseat_connection_fatal(Seat *seat, const char *message);
  942. void nullseat_update_specials_menu(Seat *seat);
  943. char *nullseat_get_ttymode(Seat *seat, const char *mode);
  944. void nullseat_set_busy_status(Seat *seat, BusyStatus status);
  945. int nullseat_verify_ssh_host_key(
  946. Seat *seat, const char *host, int port,
  947. const char *keytype, char *keystr, char *key_fingerprint,
  948. void (*callback)(void *ctx, int result), void *ctx);
  949. int nullseat_confirm_weak_crypto_primitive(
  950. Seat *seat, const char *algtype, const char *algname,
  951. void (*callback)(void *ctx, int result), void *ctx);
  952. int nullseat_confirm_weak_cached_hostkey(
  953. Seat *seat, const char *algname, const char *betteralgs,
  954. void (*callback)(void *ctx, int result), void *ctx);
  955. bool nullseat_is_never_utf8(Seat *seat);
  956. bool nullseat_is_always_utf8(Seat *seat);
  957. void nullseat_echoedit_update(Seat *seat, bool echoing, bool editing);
  958. const char *nullseat_get_x_display(Seat *seat);
  959. bool nullseat_get_windowid(Seat *seat, long *id_out);
  960. bool nullseat_get_window_pixel_size(Seat *seat, int *width, int *height);
  961. StripCtrlChars *nullseat_stripctrl_new(
  962. Seat *seat, BinarySink *bs_out, SeatInteractionContext sic);
  963. bool nullseat_set_trust_status(Seat *seat, bool trusted);
  964. bool nullseat_set_trust_status_vacuously(Seat *seat, bool trusted);
  965. /*
  966. * Seat functions provided by the platform's console-application
  967. * support module (wincons.c, uxcons.c).
  968. */
  969. void console_connection_fatal(Seat *seat, const char *message);
  970. int console_verify_ssh_host_key(
  971. Seat *seat, const char *host, int port,
  972. const char *keytype, char *keystr, char *key_fingerprint,
  973. void (*callback)(void *ctx, int result), void *ctx);
  974. int console_confirm_weak_crypto_primitive(
  975. Seat *seat, const char *algtype, const char *algname,
  976. void (*callback)(void *ctx, int result), void *ctx);
  977. int console_confirm_weak_cached_hostkey(
  978. Seat *seat, const char *algname, const char *betteralgs,
  979. void (*callback)(void *ctx, int result), void *ctx);
  980. StripCtrlChars *console_stripctrl_new(
  981. Seat *seat, BinarySink *bs_out, SeatInteractionContext sic);
  982. bool console_set_trust_status(Seat *seat, bool trusted);
  983. /*
  984. * Other centralised seat functions.
  985. */
  986. int filexfer_get_userpass_input(Seat *seat, prompts_t *p, bufchain *input);
  987. /*
  988. * Data type 'TermWin', which is a vtable encapsulating all the
  989. * functionality that Terminal expects from its containing terminal
  990. * window.
  991. */
  992. struct TermWin {
  993. const struct TermWinVtable *vt;
  994. };
  995. struct TermWinVtable {
  996. /*
  997. * All functions listed here between setup_draw_ctx and
  998. * free_draw_ctx expect to be _called_ between them too, so that
  999. * the TermWin has a drawing context currently available.
  1000. *
  1001. * (Yes, even char_width, because e.g. the Windows implementation
  1002. * of TermWin handles it by loading the currently configured font
  1003. * into the HDC and doing a GDI query.)
  1004. */
  1005. bool (*setup_draw_ctx)(TermWin *);
  1006. /* Draw text in the window, during a painting operation */
  1007. void (*draw_text)(TermWin *, int x, int y, wchar_t *text, int len,
  1008. unsigned long attrs, int line_attrs, truecolour tc);
  1009. /* Draw the visible cursor. Expects you to have called do_text
  1010. * first (because it might just draw an underline over a character
  1011. * presumed to exist already), but also expects you to pass in all
  1012. * the details of the character under the cursor (because it might
  1013. * redraw it in different colours). */
  1014. void (*draw_cursor)(TermWin *, int x, int y, wchar_t *text, int len,
  1015. unsigned long attrs, int line_attrs, truecolour tc);
  1016. /* Draw the sigil indicating that a line of text has come from
  1017. * PuTTY itself rather than the far end (defence against end-of-
  1018. * authentication spoofing) */
  1019. void (*draw_trust_sigil)(TermWin *, int x, int y);
  1020. int (*char_width)(TermWin *, int uc);
  1021. void (*free_draw_ctx)(TermWin *);
  1022. void (*set_cursor_pos)(TermWin *, int x, int y);
  1023. void (*set_raw_mouse_mode)(TermWin *, bool enable);
  1024. void (*set_scrollbar)(TermWin *, int total, int start, int page);
  1025. void (*bell)(TermWin *, int mode);
  1026. void (*clip_write)(TermWin *, int clipboard, wchar_t *text, int *attrs,
  1027. truecolour *colours, int len, bool must_deselect);
  1028. void (*clip_request_paste)(TermWin *, int clipboard);
  1029. void (*refresh)(TermWin *);
  1030. void (*request_resize)(TermWin *, int w, int h);
  1031. void (*set_title)(TermWin *, const char *title);
  1032. void (*set_icon_title)(TermWin *, const char *icontitle);
  1033. /* set_minimised and set_maximised are assumed to set two
  1034. * independent settings, rather than a single three-way
  1035. * {min,normal,max} switch. The idea is that when you un-minimise
  1036. * the window it remembers whether to go back to normal or
  1037. * maximised. */
  1038. void (*set_minimised)(TermWin *, bool minimised);
  1039. bool (*is_minimised)(TermWin *);
  1040. void (*set_maximised)(TermWin *, bool maximised);
  1041. void (*move)(TermWin *, int x, int y);
  1042. void (*set_zorder)(TermWin *, bool top);
  1043. bool (*palette_get)(TermWin *, int n, int *r, int *g, int *b);
  1044. void (*palette_set)(TermWin *, int n, int r, int g, int b);
  1045. void (*palette_reset)(TermWin *);
  1046. void (*get_pos)(TermWin *, int *x, int *y);
  1047. void (*get_pixels)(TermWin *, int *x, int *y);
  1048. const char *(*get_title)(TermWin *, bool icon);
  1049. bool (*is_utf8)(TermWin *);
  1050. };
  1051. static inline bool win_setup_draw_ctx(TermWin *win)
  1052. { return win->vt->setup_draw_ctx(win); }
  1053. static inline void win_draw_text(
  1054. TermWin *win, int x, int y, wchar_t *text, int len,
  1055. unsigned long attrs, int line_attrs, truecolour tc)
  1056. { win->vt->draw_text(win, x, y, text, len, attrs, line_attrs, tc); }
  1057. static inline void win_draw_cursor(
  1058. TermWin *win, int x, int y, wchar_t *text, int len,
  1059. unsigned long attrs, int line_attrs, truecolour tc)
  1060. { win->vt->draw_cursor(win, x, y, text, len, attrs, line_attrs, tc); }
  1061. static inline void win_draw_trust_sigil(TermWin *win, int x, int y)
  1062. { win->vt->draw_trust_sigil(win, x, y); }
  1063. static inline int win_char_width(TermWin *win, int uc)
  1064. { return win->vt->char_width(win, uc); }
  1065. static inline void win_free_draw_ctx(TermWin *win)
  1066. { win->vt->free_draw_ctx(win); }
  1067. static inline void win_set_cursor_pos(TermWin *win, int x, int y)
  1068. { win->vt->set_cursor_pos(win, x, y); }
  1069. static inline void win_set_raw_mouse_mode(TermWin *win, bool enable)
  1070. { win->vt->set_raw_mouse_mode(win, enable); }
  1071. static inline void win_set_scrollbar(TermWin *win, int t, int s, int p)
  1072. { win->vt->set_scrollbar(win, t, s, p); }
  1073. static inline void win_bell(TermWin *win, int mode)
  1074. { win->vt->bell(win, mode); }
  1075. static inline void win_clip_write(
  1076. TermWin *win, int clipboard, wchar_t *text, int *attrs,
  1077. truecolour *colours, int len, bool deselect)
  1078. { win->vt->clip_write(win, clipboard, text, attrs, colours, len, deselect); }
  1079. static inline void win_clip_request_paste(TermWin *win, int clipboard)
  1080. { win->vt->clip_request_paste(win, clipboard); }
  1081. static inline void win_refresh(TermWin *win)
  1082. { win->vt->refresh(win); }
  1083. static inline void win_request_resize(TermWin *win, int w, int h)
  1084. { win->vt->request_resize(win, w, h); }
  1085. static inline void win_set_title(TermWin *win, const char *title)
  1086. { win->vt->set_title(win, title); }
  1087. static inline void win_set_icon_title(TermWin *win, const char *icontitle)
  1088. { win->vt->set_icon_title(win, icontitle); }
  1089. static inline void win_set_minimised(TermWin *win, bool minimised)
  1090. { win->vt->set_minimised(win, minimised); }
  1091. static inline bool win_is_minimised(TermWin *win)
  1092. { return win->vt->is_minimised(win); }
  1093. static inline void win_set_maximised(TermWin *win, bool maximised)
  1094. { win->vt->set_maximised(win, maximised); }
  1095. static inline void win_move(TermWin *win, int x, int y)
  1096. { win->vt->move(win, x, y); }
  1097. static inline void win_set_zorder(TermWin *win, bool top)
  1098. { win->vt->set_zorder(win, top); }
  1099. static inline bool win_palette_get(TermWin *win, int n, int *r, int *g, int *b)
  1100. { return win->vt->palette_get(win, n, r, g, b); }
  1101. static inline void win_palette_set(TermWin *win, int n, int r, int g, int b)
  1102. { win->vt->palette_set(win, n, r, g, b); }
  1103. static inline void win_palette_reset(TermWin *win)
  1104. { win->vt->palette_reset(win); }
  1105. static inline void win_get_pos(TermWin *win, int *x, int *y)
  1106. { win->vt->get_pos(win, x, y); }
  1107. static inline void win_get_pixels(TermWin *win, int *x, int *y)
  1108. { win->vt->get_pixels(win, x, y); }
  1109. static inline const char *win_get_title(TermWin *win, bool icon)
  1110. { return win->vt->get_title(win, icon); }
  1111. static inline bool win_is_utf8(TermWin *win)
  1112. { return win->vt->is_utf8(win); }
  1113. /*
  1114. * Global functions not specific to a connection instance.
  1115. */
  1116. void nonfatal(const char *, ...);
  1117. NORETURN void modalfatalbox(const char *, ...);
  1118. NORETURN void cleanup_exit(int);
  1119. /*
  1120. * Exports from conf.c, and a big enum (via parametric macro) of
  1121. * configuration option keys.
  1122. */
  1123. #define CONFIG_OPTIONS(X) \
  1124. /* X(value-type, subkey-type, keyword) */ \
  1125. X(STR, NONE, host) \
  1126. X(INT, NONE, port) \
  1127. X(INT, NONE, protocol) /* PROT_SSH, PROT_TELNET etc */ \
  1128. X(INT, NONE, addressfamily) /* ADDRTYPE_IPV[46] or ADDRTYPE_UNSPEC */ \
  1129. X(INT, NONE, close_on_exit) /* FORCE_ON, FORCE_OFF, AUTO */ \
  1130. X(BOOL, NONE, warn_on_close) \
  1131. X(INT, NONE, ping_interval) /* in seconds */ \
  1132. X(BOOL, NONE, tcp_nodelay) \
  1133. X(BOOL, NONE, tcp_keepalives) \
  1134. X(STR, NONE, loghost) /* logical host being contacted, for host key check */ \
  1135. /* Proxy options */ \
  1136. X(STR, NONE, proxy_exclude_list) \
  1137. X(INT, NONE, proxy_dns) /* FORCE_ON, FORCE_OFF, AUTO */ \
  1138. X(BOOL, NONE, even_proxy_localhost) \
  1139. X(INT, NONE, proxy_type) /* PROXY_NONE, PROXY_SOCKS4, ... */ \
  1140. X(STR, NONE, proxy_host) \
  1141. X(INT, NONE, proxy_port) \
  1142. X(STR, NONE, proxy_username) \
  1143. X(STR, NONE, proxy_password) \
  1144. X(STR, NONE, proxy_telnet_command) \
  1145. X(INT, NONE, proxy_log_to_term) /* FORCE_ON, FORCE_OFF, AUTO */ \
  1146. /* SSH options */ \
  1147. X(STR, NONE, remote_cmd) \
  1148. X(STR, NONE, remote_cmd2) /* fallback if remote_cmd fails; never loaded or saved */ \
  1149. X(BOOL, NONE, nopty) \
  1150. X(BOOL, NONE, compression) \
  1151. X(INT, INT, ssh_kexlist) \
  1152. X(INT, INT, ssh_hklist) \
  1153. X(INT, NONE, ssh_rekey_time) /* in minutes */ \
  1154. X(STR, NONE, ssh_rekey_data) /* string encoding e.g. "100K", "2M", "1G" */ \
  1155. X(BOOL, NONE, tryagent) \
  1156. X(BOOL, NONE, agentfwd) \
  1157. X(BOOL, NONE, change_username) /* allow username switching in SSH-2 */ \
  1158. X(INT, INT, ssh_cipherlist) \
  1159. X(FILENAME, NONE, keyfile) \
  1160. /* \
  1161. * Which SSH protocol to use. \
  1162. * For historical reasons, the current legal values for CONF_sshprot \
  1163. * are: \
  1164. * 0 = SSH-1 only \
  1165. * 3 = SSH-2 only \
  1166. * We used to also support \
  1167. * 1 = SSH-1 with fallback to SSH-2 \
  1168. * 2 = SSH-2 with fallback to SSH-1 \
  1169. * and we continue to use 0/3 in storage formats rather than the more \
  1170. * obvious 1/2 to avoid surprises if someone saves a session and later \
  1171. * downgrades PuTTY. So it's easier to use these numbers internally too. \
  1172. */ \
  1173. X(INT, NONE, sshprot) \
  1174. X(BOOL, NONE, ssh2_des_cbc) /* "des-cbc" unrecommended SSH-2 cipher */ \
  1175. X(BOOL, NONE, ssh_no_userauth) /* bypass "ssh-userauth" (SSH-2 only) */ \
  1176. X(BOOL, NONE, ssh_show_banner) /* show USERAUTH_BANNERs (SSH-2 only) */ \
  1177. X(BOOL, NONE, try_tis_auth) \
  1178. X(BOOL, NONE, try_ki_auth) \
  1179. X(BOOL, NONE, try_gssapi_auth) /* attempt gssapi auth via ssh userauth */ \
  1180. X(BOOL, NONE, try_gssapi_kex) /* attempt gssapi auth via ssh kex */ \
  1181. X(BOOL, NONE, gssapifwd) /* forward tgt via gss */ \
  1182. X(INT, NONE, gssapirekey) /* KEXGSS refresh interval (mins) */ \
  1183. X(INT, INT, ssh_gsslist) /* preference order for local GSS libs */ \
  1184. X(FILENAME, NONE, ssh_gss_custom) \
  1185. X(BOOL, NONE, ssh_subsys) /* run a subsystem rather than a command */ \
  1186. X(BOOL, NONE, ssh_subsys2) /* fallback to go with remote_cmd_ptr2 */ \
  1187. X(BOOL, NONE, ssh_no_shell) /* avoid running a shell */ \
  1188. X(STR, NONE, ssh_nc_host) /* host to connect to in `nc' mode */ \
  1189. X(INT, NONE, ssh_nc_port) /* port to connect to in `nc' mode */ \
  1190. /* Telnet options */ \
  1191. X(STR, NONE, termtype) \
  1192. X(STR, NONE, termspeed) \
  1193. X(STR, STR, ttymodes) /* values are "Vvalue" or "A" */ \
  1194. X(STR, STR, environmt) \
  1195. X(STR, NONE, username) \
  1196. X(BOOL, NONE, username_from_env) \
  1197. X(STR, NONE, localusername) \
  1198. X(BOOL, NONE, rfc_environ) \
  1199. X(BOOL, NONE, passive_telnet) \
  1200. /* Serial port options */ \
  1201. X(STR, NONE, serline) \
  1202. X(INT, NONE, serspeed) \
  1203. X(INT, NONE, serdatabits) \
  1204. X(INT, NONE, serstopbits) \
  1205. X(INT, NONE, serparity) /* SER_PAR_NONE, SER_PAR_ODD, ... */ \
  1206. X(INT, NONE, serflow) /* SER_FLOW_NONE, SER_FLOW_XONXOFF, ... */ \
  1207. /* Keyboard options */ \
  1208. X(BOOL, NONE, bksp_is_delete) \
  1209. X(BOOL, NONE, rxvt_homeend) \
  1210. X(INT, NONE, funky_type) /* FUNKY_XTERM, FUNKY_LINUX, ... */ \
  1211. X(BOOL, NONE, no_applic_c) /* totally disable app cursor keys */ \
  1212. X(BOOL, NONE, no_applic_k) /* totally disable app keypad */ \
  1213. X(BOOL, NONE, no_mouse_rep) /* totally disable mouse reporting */ \
  1214. X(BOOL, NONE, no_remote_resize) /* disable remote resizing */ \
  1215. X(BOOL, NONE, no_alt_screen) /* disable alternate screen */ \
  1216. X(BOOL, NONE, no_remote_wintitle) /* disable remote retitling */ \
  1217. X(BOOL, NONE, no_remote_clearscroll) /* disable ESC[3J */ \
  1218. X(BOOL, NONE, no_dbackspace) /* disable destructive backspace */ \
  1219. X(BOOL, NONE, no_remote_charset) /* disable remote charset config */ \
  1220. X(INT, NONE, remote_qtitle_action) /* remote win title query action
  1221. * (TITLE_NONE, TITLE_EMPTY, ...) */ \
  1222. X(BOOL, NONE, app_cursor) \
  1223. X(BOOL, NONE, app_keypad) \
  1224. X(BOOL, NONE, nethack_keypad) \
  1225. X(BOOL, NONE, telnet_keyboard) \
  1226. X(BOOL, NONE, telnet_newline) \
  1227. X(BOOL, NONE, alt_f4) /* is it special? */ \
  1228. X(BOOL, NONE, alt_space) /* is it special? */ \
  1229. X(BOOL, NONE, alt_only) /* is it special? */ \
  1230. X(INT, NONE, localecho) /* FORCE_ON, FORCE_OFF, AUTO */ \
  1231. X(INT, NONE, localedit) /* FORCE_ON, FORCE_OFF, AUTO */ \
  1232. X(BOOL, NONE, alwaysontop) \
  1233. X(BOOL, NONE, fullscreenonaltenter) \
  1234. X(BOOL, NONE, scroll_on_key) \
  1235. X(BOOL, NONE, scroll_on_disp) \
  1236. X(BOOL, NONE, erase_to_scrollback) \
  1237. X(BOOL, NONE, compose_key) \
  1238. X(BOOL, NONE, ctrlaltkeys) \
  1239. X(BOOL, NONE, osx_option_meta) \
  1240. X(BOOL, NONE, osx_command_meta) \
  1241. X(STR, NONE, wintitle) /* initial window title */ \
  1242. /* Terminal options */ \
  1243. X(INT, NONE, savelines) \
  1244. X(BOOL, NONE, dec_om) \
  1245. X(BOOL, NONE, wrap_mode) \
  1246. X(BOOL, NONE, lfhascr) \
  1247. X(INT, NONE, cursor_type) /* 0=block 1=underline 2=vertical */ \
  1248. X(BOOL, NONE, blink_cur) \
  1249. X(INT, NONE, beep) /* BELL_DISABLED, BELL_DEFAULT, ... */ \
  1250. X(INT, NONE, beep_ind) /* B_IND_DISABLED, B_IND_FLASH, ... */ \
  1251. X(BOOL, NONE, bellovl) /* bell overload protection active? */ \
  1252. X(INT, NONE, bellovl_n) /* number of bells to cause overload */ \
  1253. X(INT, NONE, bellovl_t) /* time interval for overload (seconds) */ \
  1254. X(INT, NONE, bellovl_s) /* period of silence to re-enable bell (s) */ \
  1255. X(FILENAME, NONE, bell_wavefile) \
  1256. X(BOOL, NONE, scrollbar) \
  1257. X(BOOL, NONE, scrollbar_in_fullscreen) \
  1258. X(INT, NONE, resize_action) /* RESIZE_TERM, RESIZE_DISABLED, ... */ \
  1259. X(BOOL, NONE, bce) \
  1260. X(BOOL, NONE, blinktext) \
  1261. X(BOOL, NONE, win_name_always) \
  1262. X(INT, NONE, width) \
  1263. X(INT, NONE, height) \
  1264. X(FONT, NONE, font) \
  1265. X(INT, NONE, font_quality) /* FQ_DEFAULT, FQ_ANTIALIASED, ... */ \
  1266. X(FILENAME, NONE, logfilename) \
  1267. X(INT, NONE, logtype) /* LGTYP_NONE, LGTYPE_ASCII, ... */ \
  1268. X(INT, NONE, logxfovr) /* LGXF_OVR, LGXF_APN, LGXF_ASK */ \
  1269. X(BOOL, NONE, logflush) \
  1270. X(BOOL, NONE, logheader) \
  1271. X(BOOL, NONE, logomitpass) \
  1272. X(BOOL, NONE, logomitdata) \
  1273. X(BOOL, NONE, hide_mouseptr) \
  1274. X(BOOL, NONE, sunken_edge) \
  1275. X(INT, NONE, window_border) /* in pixels */ \
  1276. X(STR, NONE, answerback) \
  1277. X(STR, NONE, printer) \
  1278. X(BOOL, NONE, no_arabicshaping) \
  1279. X(BOOL, NONE, no_bidi) \
  1280. /* Colour options */ \
  1281. X(BOOL, NONE, ansi_colour) \
  1282. X(BOOL, NONE, xterm_256_colour) \
  1283. X(BOOL, NONE, true_colour) \
  1284. X(BOOL, NONE, system_colour) \
  1285. X(BOOL, NONE, try_palette) \
  1286. X(INT, NONE, bold_style) /* 1=font 2=colour (3=both) */ \
  1287. X(INT, INT, colours) \
  1288. /* Selection options */ \
  1289. X(INT, NONE, mouse_is_xterm) /* 0=compromise 1=xterm 2=Windows */ \
  1290. X(BOOL, NONE, rect_select) \
  1291. X(BOOL, NONE, paste_controls) \
  1292. X(BOOL, NONE, rawcnp) \
  1293. X(BOOL, NONE, utf8linedraw) \
  1294. X(BOOL, NONE, rtf_paste) \
  1295. X(BOOL, NONE, mouse_override) \
  1296. X(INT, INT, wordness) \
  1297. X(BOOL, NONE, mouseautocopy) \
  1298. X(INT, NONE, mousepaste) /* CLIPUI_IMPLICIT, CLIPUI_EXPLICIT, ... */ \
  1299. X(INT, NONE, ctrlshiftins) /* CLIPUI_IMPLICIT, CLIPUI_EXPLICIT, ... */ \
  1300. X(INT, NONE, ctrlshiftcv) /* CLIPUI_IMPLICIT, CLIPUI_EXPLICIT, ... */ \
  1301. X(STR, NONE, mousepaste_custom) \
  1302. X(STR, NONE, ctrlshiftins_custom) \
  1303. X(STR, NONE, ctrlshiftcv_custom) \
  1304. /* translations */ \
  1305. X(INT, NONE, vtmode) /* VT_XWINDOWS, VT_OEMANSI, ... */ \
  1306. X(STR, NONE, line_codepage) \
  1307. X(BOOL, NONE, cjk_ambig_wide) \
  1308. X(BOOL, NONE, utf8_override) \
  1309. X(BOOL, NONE, xlat_capslockcyr) \
  1310. /* X11 forwarding */ \
  1311. X(BOOL, NONE, x11_forward) \
  1312. X(STR, NONE, x11_display) \
  1313. X(INT, NONE, x11_auth) /* X11_NO_AUTH, X11_MIT, X11_XDM */ \
  1314. X(FILENAME, NONE, xauthfile) \
  1315. /* port forwarding */ \
  1316. X(BOOL, NONE, lport_acceptall) /* accept conns from hosts other than localhost */ \
  1317. X(BOOL, NONE, rport_acceptall) /* same for remote forwarded ports (SSH-2 only) */ \
  1318. /* \
  1319. * Subkeys for 'portfwd' can have the following forms: \
  1320. * \
  1321. * [LR]localport \
  1322. * [LR]localaddr:localport \
  1323. * \
  1324. * Dynamic forwardings are indicated by an 'L' key, and the \
  1325. * special value "D". For all other forwardings, the value \
  1326. * should be of the form 'host:port'. \
  1327. */ \
  1328. X(STR, STR, portfwd) \
  1329. /* SSH bug compatibility modes. All FORCE_ON/FORCE_OFF/AUTO */ \
  1330. X(INT, NONE, sshbug_ignore1) \
  1331. X(INT, NONE, sshbug_plainpw1) \
  1332. X(INT, NONE, sshbug_rsa1) \
  1333. X(INT, NONE, sshbug_hmac2) \
  1334. X(INT, NONE, sshbug_derivekey2) \
  1335. X(INT, NONE, sshbug_rsapad2) \
  1336. X(INT, NONE, sshbug_pksessid2) \
  1337. X(INT, NONE, sshbug_rekey2) \
  1338. X(INT, NONE, sshbug_maxpkt2) \
  1339. X(INT, NONE, sshbug_ignore2) \
  1340. X(INT, NONE, sshbug_oldgex2) \
  1341. X(INT, NONE, sshbug_winadj) \
  1342. X(INT, NONE, sshbug_chanreq) \
  1343. /* \
  1344. * ssh_simple means that we promise never to open any channel \
  1345. * other than the main one, which means it can safely use a very \
  1346. * large window in SSH-2. \
  1347. */ \
  1348. X(BOOL, NONE, ssh_simple) \
  1349. X(BOOL, NONE, ssh_connection_sharing) \
  1350. X(BOOL, NONE, ssh_connection_sharing_upstream) \
  1351. X(BOOL, NONE, ssh_connection_sharing_downstream) \
  1352. /*
  1353. * ssh_manual_hostkeys is conceptually a set rather than a
  1354. * dictionary: the string subkeys are the important thing, and the
  1355. * actual values to which those subkeys map are all "".
  1356. */ \
  1357. X(STR, STR, ssh_manual_hostkeys) \
  1358. /* Options for pterm. Should split out into platform-dependent part. */ \
  1359. X(BOOL, NONE, stamp_utmp) \
  1360. X(BOOL, NONE, login_shell) \
  1361. X(BOOL, NONE, scrollbar_on_left) \
  1362. X(BOOL, NONE, shadowbold) \
  1363. X(FONT, NONE, boldfont) \
  1364. X(FONT, NONE, widefont) \
  1365. X(FONT, NONE, wideboldfont) \
  1366. X(INT, NONE, shadowboldoffset) /* in pixels */ \
  1367. X(BOOL, NONE, crhaslf) \
  1368. X(STR, NONE, winclass) \
  1369. /* MPEXT BEGIN */ \
  1370. X(INT, NONE, connect_timeout) \
  1371. X(INT, NONE, sndbuf) \
  1372. X(STR, NONE, srcaddr) \
  1373. X(BOOL, NONE, force_remote_cmd2) \
  1374. X(BOOL, NONE, change_password) \
  1375. /* MPEXT END */ \
  1376. /* end of list */
  1377. /* Now define the actual enum of option keywords using that macro. */
  1378. #define CONF_ENUM_DEF(valtype, keytype, keyword) CONF_ ## keyword,
  1379. enum config_primary_key { CONFIG_OPTIONS(CONF_ENUM_DEF) N_CONFIG_OPTIONS };
  1380. #undef CONF_ENUM_DEF
  1381. #define NCFGCOLOURS 22 /* number of colours in CONF_colours above */
  1382. /* Functions handling configuration structures. */
  1383. Conf *conf_new(void); /* create an empty configuration */
  1384. void conf_free(Conf *conf);
  1385. Conf *conf_copy(Conf *oldconf);
  1386. void conf_copy_into(Conf *dest, Conf *src);
  1387. /* Mandatory accessor functions: enforce by assertion that keys exist. */
  1388. bool conf_get_bool(Conf *conf, int key);
  1389. int conf_get_int(Conf *conf, int key);
  1390. int conf_get_int_int(Conf *conf, int key, int subkey);
  1391. char *conf_get_str(Conf *conf, int key); /* result still owned by conf */
  1392. char *conf_get_str_str(Conf *conf, int key, const char *subkey);
  1393. Filename *conf_get_filename(Conf *conf, int key);
  1394. FontSpec *conf_get_fontspec(Conf *conf, int key); /* still owned by conf */
  1395. /* Optional accessor function: return NULL if key does not exist. */
  1396. char *conf_get_str_str_opt(Conf *conf, int key, const char *subkey);
  1397. /* Accessor function to step through a string-subkeyed list.
  1398. * Returns the next subkey after the provided one, or the first if NULL.
  1399. * Returns NULL if there are none left.
  1400. * Both the return value and *subkeyout are still owned by conf. */
  1401. char *conf_get_str_strs(Conf *conf, int key, char *subkeyin, char **subkeyout);
  1402. /* Return the nth string subkey in a list. Owned by conf. NULL if beyond end */
  1403. char *conf_get_str_nthstrkey(Conf *conf, int key, int n);
  1404. /* Functions to set entries in configuration. Always copy their inputs. */
  1405. void conf_set_bool(Conf *conf, int key, bool value);
  1406. void conf_set_int(Conf *conf, int key, int value);
  1407. void conf_set_int_int(Conf *conf, int key, int subkey, int value);
  1408. void conf_set_str(Conf *conf, int key, const char *value);
  1409. void conf_set_str_str(Conf *conf, int key,
  1410. const char *subkey, const char *val);
  1411. void conf_del_str_str(Conf *conf, int key, const char *subkey);
  1412. void conf_set_filename(Conf *conf, int key, const Filename *val);
  1413. void conf_set_fontspec(Conf *conf, int key, const FontSpec *val);
  1414. /* Serialisation functions for Duplicate Session */
  1415. void conf_serialise(BinarySink *bs, Conf *conf);
  1416. bool conf_deserialise(Conf *conf, BinarySource *src);/*returns true on success*/
  1417. /*
  1418. * Functions to copy, free, serialise and deserialise FontSpecs.
  1419. * Provided per-platform, to go with the platform's idea of a
  1420. * FontSpec's contents.
  1421. */
  1422. FontSpec *fontspec_copy(const FontSpec *f);
  1423. void fontspec_free(FontSpec *f);
  1424. void fontspec_serialise(BinarySink *bs, FontSpec *f);
  1425. FontSpec *fontspec_deserialise(BinarySource *src);
  1426. /*
  1427. * Exports from noise.c.
  1428. */
  1429. typedef enum NoiseSourceId {
  1430. NOISE_SOURCE_TIME,
  1431. NOISE_SOURCE_IOID,
  1432. NOISE_SOURCE_IOLEN,
  1433. NOISE_SOURCE_KEY,
  1434. NOISE_SOURCE_MOUSEBUTTON,
  1435. NOISE_SOURCE_MOUSEPOS,
  1436. NOISE_SOURCE_MEMINFO,
  1437. NOISE_SOURCE_STAT,
  1438. NOISE_SOURCE_RUSAGE,
  1439. NOISE_SOURCE_FGWINDOW,
  1440. NOISE_SOURCE_CAPTURE,
  1441. NOISE_SOURCE_CLIPBOARD,
  1442. NOISE_SOURCE_QUEUE,
  1443. NOISE_SOURCE_CURSORPOS,
  1444. NOISE_SOURCE_THREADTIME,
  1445. NOISE_SOURCE_PROCTIME,
  1446. NOISE_SOURCE_PERFCOUNT,
  1447. NOISE_MAX_SOURCES
  1448. } NoiseSourceId;
  1449. void noise_get_heavy(void (*func) (void *, int));
  1450. void noise_get_light(void (*func) (void *, int));
  1451. void noise_regular(void);
  1452. void noise_ultralight(NoiseSourceId id, unsigned long data);
  1453. void random_save_seed(void);
  1454. void random_destroy_seed(void);
  1455. /*
  1456. * Exports from settings.c.
  1457. *
  1458. * load_settings() and do_defaults() return false if the provided
  1459. * session name didn't actually exist. But they still fill in the
  1460. * provided Conf with _something_.
  1461. */
  1462. const struct BackendVtable *backend_vt_from_name(const char *name);
  1463. const struct BackendVtable *backend_vt_from_proto(int proto);
  1464. char *get_remote_username(Conf *conf); /* dynamically allocated */
  1465. char *save_settings(const char *section, Conf *conf);
  1466. void save_open_settings(settings_w *sesskey, Conf *conf);
  1467. bool load_settings(const char *section, Conf *conf);
  1468. void load_open_settings(settings_r *sesskey, Conf *conf);
  1469. void get_sesslist(struct sesslist *, bool allocate);
  1470. bool do_defaults(const char *, Conf *);
  1471. void registry_cleanup(void);
  1472. /*
  1473. * Functions used by settings.c to provide platform-specific
  1474. * default settings.
  1475. *
  1476. * (The integer one is expected to return `def' if it has no clear
  1477. * opinion of its own. This is because there's no integer value
  1478. * which I can reliably set aside to indicate `nil'. The string
  1479. * function is perfectly all right returning NULL, of course. The
  1480. * Filename and FontSpec functions are _not allowed_ to fail to
  1481. * return, since these defaults _must_ be per-platform.)
  1482. *
  1483. * The 'Filename *' returned by platform_default_filename, and the
  1484. * 'FontSpec *' returned by platform_default_fontspec, have ownership
  1485. * transferred to the caller, and must be freed.
  1486. */
  1487. char *platform_default_s(const char *name);
  1488. bool platform_default_b(const char *name, bool def);
  1489. int platform_default_i(const char *name, int def);
  1490. Filename *platform_default_filename(const char *name);
  1491. FontSpec *platform_default_fontspec(const char *name);
  1492. /*
  1493. * Exports from terminal.c.
  1494. */
  1495. Terminal *term_init(Conf *, struct unicode_data *, TermWin *);
  1496. void term_free(Terminal *);
  1497. void term_size(Terminal *, int, int, int);
  1498. void term_paint(Terminal *, int, int, int, int, bool);
  1499. void term_scroll(Terminal *, int, int);
  1500. void term_scroll_to_selection(Terminal *, int);
  1501. void term_pwron(Terminal *, bool);
  1502. void term_clrsb(Terminal *);
  1503. void term_mouse(Terminal *, Mouse_Button, Mouse_Button, Mouse_Action,
  1504. int, int, bool, bool, bool);
  1505. void term_key(Terminal *, Key_Sym, wchar_t *, size_t, unsigned int,
  1506. unsigned int);
  1507. void term_lost_clipboard_ownership(Terminal *, int clipboard);
  1508. void term_update(Terminal *);
  1509. void term_invalidate(Terminal *);
  1510. void term_blink(Terminal *, bool set_cursor);
  1511. void term_do_paste(Terminal *, const wchar_t *, int);
  1512. void term_nopaste(Terminal *);
  1513. void term_copyall(Terminal *, const int *, int);
  1514. void term_reconfig(Terminal *, Conf *);
  1515. void term_request_copy(Terminal *, const int *clipboards, int n_clipboards);
  1516. void term_request_paste(Terminal *, int clipboard);
  1517. void term_seen_key_event(Terminal *);
  1518. size_t term_data(Terminal *, bool is_stderr, const void *data, size_t len);
  1519. void term_provide_backend(Terminal *term, Backend *backend);
  1520. void term_provide_logctx(Terminal *term, LogContext *logctx);
  1521. void term_set_focus(Terminal *term, bool has_focus);
  1522. char *term_get_ttymode(Terminal *term, const char *mode);
  1523. int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input);
  1524. void term_set_trust_status(Terminal *term, bool trusted);
  1525. void term_keyinput(Terminal *, int codepage, const void *buf, int len);
  1526. void term_keyinputw(Terminal *, const wchar_t * widebuf, int len);
  1527. typedef enum SmallKeypadKey {
  1528. SKK_HOME, SKK_END, SKK_INSERT, SKK_DELETE, SKK_PGUP, SKK_PGDN,
  1529. } SmallKeypadKey;
  1530. int format_arrow_key(char *buf, Terminal *term, int xkey, bool ctrl);
  1531. int format_function_key(char *buf, Terminal *term, int key_number,
  1532. bool shift, bool ctrl);
  1533. int format_small_keypad_key(char *buf, Terminal *term, SmallKeypadKey key);
  1534. int format_numeric_keypad_key(char *buf, Terminal *term, char key,
  1535. bool shift, bool ctrl);
  1536. /*
  1537. * Exports from logging.c.
  1538. */
  1539. struct LogPolicyVtable {
  1540. /*
  1541. * Pass Event Log entries on from LogContext to the front end,
  1542. * which might write them to standard error or save them for a GUI
  1543. * list box or other things.
  1544. */
  1545. void (*eventlog)(LogPolicy *lp, const char *event);
  1546. /*
  1547. * Ask what to do about the specified output log file already
  1548. * existing. Can return four values:
  1549. *
  1550. * - 2 means overwrite the log file
  1551. * - 1 means append to the log file
  1552. * - 0 means cancel logging for this session
  1553. * - -1 means please wait, and callback() will be called with one
  1554. * of those options.
  1555. */
  1556. int (*askappend)(LogPolicy *lp, Filename *filename,
  1557. void (*callback)(void *ctx, int result), void *ctx);
  1558. /*
  1559. * Emergency logging when the log file itself can't be opened,
  1560. * which typically means we want to shout about it more loudly
  1561. * than a mere Event Log entry.
  1562. *
  1563. * One reasonable option is to send it to the same place that
  1564. * stderr output from the main session goes (so, either a console
  1565. * tool's actual stderr, or a terminal window). In many cases this
  1566. * is unlikely to cause this error message to turn up
  1567. * embarrassingly in a log file of real server output, because the
  1568. * whole point is that we haven't managed to open any such log
  1569. * file :-)
  1570. */
  1571. void (*logging_error)(LogPolicy *lp, const char *event);
  1572. };
  1573. struct LogPolicy {
  1574. const LogPolicyVtable *vt;
  1575. };
  1576. static inline void lp_eventlog(LogPolicy *lp, const char *event)
  1577. { lp->vt->eventlog(lp, event); }
  1578. static inline int lp_askappend(
  1579. LogPolicy *lp, Filename *filename,
  1580. void (*callback)(void *ctx, int result), void *ctx)
  1581. { return lp->vt->askappend(lp, filename, callback, ctx); }
  1582. static inline void lp_logging_error(LogPolicy *lp, const char *event)
  1583. { lp->vt->logging_error(lp, event); }
  1584. LogContext *log_init(LogPolicy *lp, Conf *conf);
  1585. void log_free(LogContext *logctx);
  1586. void log_reconfig(LogContext *logctx, Conf *conf);
  1587. void logfopen(LogContext *logctx);
  1588. void logfclose(LogContext *logctx);
  1589. void logtraffic(LogContext *logctx, unsigned char c, int logmode);
  1590. void logflush(LogContext *logctx);
  1591. void logevent(LogContext *logctx, const char *event);
  1592. void logeventf(LogContext *logctx, const char *fmt, ...);
  1593. void logeventvf(LogContext *logctx, const char *fmt, va_list ap);
  1594. /*
  1595. * Pass a dynamically allocated string to logevent and immediately
  1596. * free it. Intended for use by wrapper macros which pass the return
  1597. * value of dupprintf straight to this.
  1598. */
  1599. void logevent_and_free(LogContext *logctx, char *event);
  1600. enum { PKT_INCOMING, PKT_OUTGOING };
  1601. enum { PKTLOG_EMIT, PKTLOG_BLANK, PKTLOG_OMIT };
  1602. struct logblank_t {
  1603. int offset;
  1604. int len;
  1605. int type;
  1606. };
  1607. void log_packet(LogContext *logctx, int direction, int type,
  1608. const char *texttype, const void *data, size_t len,
  1609. int n_blanks, const struct logblank_t *blanks,
  1610. const unsigned long *sequence,
  1611. unsigned downstream_id, const char *additional_log_text);
  1612. /* This is defined by applications that have an obvious logging
  1613. * destination like standard error or the GUI. */
  1614. extern LogPolicy default_logpolicy[1];
  1615. /*
  1616. * Exports from testback.c
  1617. */
  1618. extern const struct BackendVtable null_backend;
  1619. extern const struct BackendVtable loop_backend;
  1620. /*
  1621. * Exports from raw.c.
  1622. */
  1623. extern const struct BackendVtable raw_backend;
  1624. /*
  1625. * Exports from rlogin.c.
  1626. */
  1627. extern const struct BackendVtable rlogin_backend;
  1628. /*
  1629. * Exports from telnet.c.
  1630. */
  1631. extern const struct BackendVtable telnet_backend;
  1632. /*
  1633. * Exports from ssh.c.
  1634. */
  1635. extern const struct BackendVtable ssh_backend;
  1636. /*
  1637. * Exports from ldisc.c.
  1638. */
  1639. Ldisc *ldisc_create(Conf *, Terminal *, Backend *, Seat *);
  1640. void ldisc_configure(Ldisc *, Conf *);
  1641. void ldisc_free(Ldisc *);
  1642. void ldisc_send(Ldisc *, const void *buf, int len, bool interactive);
  1643. void ldisc_echoedit_update(Ldisc *);
  1644. /*
  1645. * Exports from sshrand.c.
  1646. */
  1647. void random_add_noise(NoiseSourceId source, const void *noise, int length);
  1648. void random_read(void *buf, size_t size);
  1649. void random_get_savedata(void **data, int *len);
  1650. extern int random_active;
  1651. /* The random number subsystem is activated if at least one other entity
  1652. * within the program expresses an interest in it. So each SSH session
  1653. * calls random_ref on startup and random_unref on shutdown. */
  1654. void random_ref(void);
  1655. void random_unref(void);
  1656. /* random_clear is equivalent to calling random_unref as many times as
  1657. * necessary to shut down the global PRNG instance completely. It's
  1658. * not needed in normal applications, but the command-line PuTTYgen
  1659. * test finds it useful to clean up after each invocation of the
  1660. * logical main() no matter whether it needed random numbers or
  1661. * not. */
  1662. void random_clear(void);
  1663. /* random_setup_special is used by PuTTYgen. It makes an extra-big
  1664. * random number generator. */
  1665. void random_setup_special();
  1666. /* Manually drop a random seed into the random number generator, e.g.
  1667. * just before generating a key. */
  1668. void random_reseed(ptrlen seed);
  1669. /* Limit on how much entropy is worth putting into the generator (bits). */
  1670. size_t random_seed_bits(void);
  1671. /*
  1672. * Exports from pinger.c.
  1673. */
  1674. typedef struct Pinger Pinger;
  1675. Pinger *pinger_new(Conf *conf, Backend *backend);
  1676. void pinger_reconfig(Pinger *, Conf *oldconf, Conf *newconf);
  1677. void pinger_free(Pinger *);
  1678. /*
  1679. * Exports from misc.c.
  1680. */
  1681. #include "misc.h"
  1682. bool conf_launchable(Conf *conf);
  1683. char const *conf_dest(Conf *conf);
  1684. /*
  1685. * Exports from sessprep.c.
  1686. */
  1687. void prepare_session(Conf *conf);
  1688. /*
  1689. * Exports from sercfg.c.
  1690. */
  1691. void ser_setup_config_box(struct controlbox *b, bool midsession,
  1692. int parity_mask, int flow_mask);
  1693. /*
  1694. * Exports from version.c.
  1695. */
  1696. extern const char ver[];
  1697. extern const char commitid[];
  1698. /*
  1699. * Exports from unicode.c.
  1700. */
  1701. #ifndef CP_UTF8
  1702. #define CP_UTF8 65001
  1703. #endif
  1704. /* void init_ucs(void); -- this is now in platform-specific headers */
  1705. bool is_dbcs_leadbyte(int codepage, char byte);
  1706. int mb_to_wc(int codepage, int flags, const char *mbstr, int mblen,
  1707. wchar_t *wcstr, int wclen);
  1708. int wc_to_mb(int codepage, int flags, const wchar_t *wcstr, int wclen,
  1709. char *mbstr, int mblen, const char *defchr,
  1710. struct unicode_data *ucsdata);
  1711. wchar_t xlat_uskbd2cyrllic(int ch);
  1712. int check_compose(int first, int second);
  1713. int decode_codepage(char *cp_name);
  1714. const char *cp_enumerate (int index);
  1715. const char *cp_name(int codepage);
  1716. void get_unitab(int codepage, wchar_t * unitab, int ftype);
  1717. /*
  1718. * Exports from wcwidth.c
  1719. */
  1720. int mk_wcwidth(unsigned int ucs);
  1721. int mk_wcswidth(const unsigned int *pwcs, size_t n);
  1722. int mk_wcwidth_cjk(unsigned int ucs);
  1723. int mk_wcswidth_cjk(const unsigned int *pwcs, size_t n);
  1724. /*
  1725. * Exports from pageantc.c.
  1726. *
  1727. * agent_query returns NULL for here's-a-response, and non-NULL for
  1728. * query-in- progress. In the latter case there will be a call to
  1729. * `callback' at some future point, passing callback_ctx as the first
  1730. * parameter and the actual reply data as the second and third.
  1731. *
  1732. * The response may be a NULL pointer (in either of the synchronous
  1733. * or asynchronous cases), which indicates failure to receive a
  1734. * response.
  1735. *
  1736. * When the return from agent_query is not NULL, it identifies the
  1737. * in-progress query in case it needs to be cancelled. If
  1738. * agent_cancel_query is called, then the pending query is destroyed
  1739. * and the callback will not be called. (E.g. if you're going to throw
  1740. * away the thing you were using as callback_ctx.)
  1741. *
  1742. * Passing a null pointer as callback forces agent_query to behave
  1743. * synchronously, i.e. it will block if necessary, and guarantee to
  1744. * return NULL. The wrapper function agent_query_synchronous() makes
  1745. * this easier.
  1746. */
  1747. typedef struct agent_pending_query agent_pending_query;
  1748. agent_pending_query *agent_query(
  1749. strbuf *in, void **out, int *outlen,
  1750. void (*callback)(void *, void *, int), void *callback_ctx);
  1751. void agent_cancel_query(agent_pending_query *);
  1752. void agent_query_synchronous(strbuf *in, void **out, int *outlen);
  1753. bool agent_exists(void);
  1754. /*
  1755. * Exports from wildcard.c
  1756. */
  1757. const char *wc_error(int value);
  1758. int wc_match_pl(const char *wildcard, ptrlen target);
  1759. int wc_match(const char *wildcard, const char *target);
  1760. bool wc_unescape(char *output, const char *wildcard);
  1761. /*
  1762. * Exports from frontend (windlg.c etc)
  1763. */
  1764. void pgp_fingerprints(void);
  1765. /*
  1766. * have_ssh_host_key() just returns true if a key of that type is
  1767. * already cached and false otherwise.
  1768. */
  1769. bool have_ssh_host_key(Seat *seat, const char *host, int port, const char *keytype);
  1770. void display_banner(Seat *seat, const char* banner, int size); // WINSCP
  1771. /*
  1772. * Exports from console frontends (wincons.c, uxcons.c)
  1773. * that aren't equivalents to things in windlg.c et al.
  1774. */
  1775. extern bool console_batch_mode, console_antispoof_prompt;
  1776. int console_get_userpass_input(prompts_t *p);
  1777. bool is_interactive(void);
  1778. void console_print_error_msg(const char *prefix, const char *msg);
  1779. void console_print_error_msg_fmt_v(
  1780. const char *prefix, const char *fmt, va_list ap);
  1781. void console_print_error_msg_fmt(const char *prefix, const char *fmt, ...);
  1782. /*
  1783. * Exports from printing.c.
  1784. */
  1785. typedef struct printer_enum_tag printer_enum;
  1786. typedef struct printer_job_tag printer_job;
  1787. printer_enum *printer_start_enum(int *nprinters);
  1788. char *printer_get_name(printer_enum *, int);
  1789. void printer_finish_enum(printer_enum *);
  1790. printer_job *printer_start_job(char *printer);
  1791. void printer_job_data(printer_job *, const void *, size_t);
  1792. void printer_finish_job(printer_job *);
  1793. /*
  1794. * Exports from cmdline.c (and also cmdline_error(), which is
  1795. * defined differently in various places and required _by_
  1796. * cmdline.c).
  1797. *
  1798. * Note that cmdline_process_param takes a const option string, but a
  1799. * writable argument string. That's not a mistake - that's so it can
  1800. * zero out password arguments in the hope of not having them show up
  1801. * avoidably in Unix 'ps'.
  1802. */
  1803. int cmdline_process_param(const char *, char *, int, Conf *);
  1804. void cmdline_run_saved(Conf *);
  1805. void cmdline_cleanup(void);
  1806. int cmdline_get_passwd_input(prompts_t *p);
  1807. bool cmdline_host_ok(Conf *);
  1808. #define TOOLTYPE_FILETRANSFER 1
  1809. #define TOOLTYPE_NONNETWORK 2
  1810. #define TOOLTYPE_HOST_ARG 4
  1811. #define TOOLTYPE_HOST_ARG_CAN_BE_SESSION 8
  1812. #define TOOLTYPE_HOST_ARG_PROTOCOL_PREFIX 16
  1813. #define TOOLTYPE_HOST_ARG_FROM_LAUNCHABLE_LOAD 32
  1814. #define TOOLTYPE_PORT_ARG 64
  1815. extern int cmdline_tooltype;
  1816. void cmdline_error(const char *, ...);
  1817. /*
  1818. * Exports from config.c.
  1819. */
  1820. struct controlbox;
  1821. union control;
  1822. void conf_radiobutton_handler(union control *ctrl, dlgparam *dlg,
  1823. void *data, int event);
  1824. #define CHECKBOX_INVERT (1<<30)
  1825. void conf_checkbox_handler(union control *ctrl, dlgparam *dlg,
  1826. void *data, int event);
  1827. void conf_editbox_handler(union control *ctrl, dlgparam *dlg,
  1828. void *data, int event);
  1829. void conf_filesel_handler(union control *ctrl, dlgparam *dlg,
  1830. void *data, int event);
  1831. void conf_fontsel_handler(union control *ctrl, dlgparam *dlg,
  1832. void *data, int event);
  1833. /* Much more special-purpose function needed by sercfg.c */
  1834. void config_protocolbuttons_handler(union control *, dlgparam *, void *, int);
  1835. void setup_config_box(struct controlbox *b, bool midsession,
  1836. int protocol, int protcfginfo);
  1837. /*
  1838. * Exports from minibidi.c.
  1839. */
  1840. #define BIDI_CHAR_INDEX_NONE ((unsigned short)-1)
  1841. typedef struct bidi_char {
  1842. unsigned int origwc, wc;
  1843. unsigned short index, nchars;
  1844. } bidi_char;
  1845. int do_bidi(bidi_char *line, int count);
  1846. int do_shape(bidi_char *line, bidi_char *to, int count);
  1847. bool is_rtl(int c);
  1848. /*
  1849. * X11 auth mechanisms we know about.
  1850. */
  1851. enum {
  1852. X11_NO_AUTH,
  1853. X11_MIT, /* MIT-MAGIC-COOKIE-1 */
  1854. X11_XDM, /* XDM-AUTHORIZATION-1 */
  1855. X11_NAUTHS
  1856. };
  1857. extern const char *const x11_authnames[]; /* declared in x11fwd.c */
  1858. /*
  1859. * An enum for the copy-paste UI action configuration.
  1860. */
  1861. enum {
  1862. CLIPUI_NONE, /* UI action has no copy/paste effect */
  1863. CLIPUI_IMPLICIT, /* use the default clipboard implicit in mouse actions */
  1864. CLIPUI_EXPLICIT, /* use the default clipboard for explicit Copy/Paste */
  1865. CLIPUI_CUSTOM, /* use a named clipboard (on systems that support it) */
  1866. };
  1867. /*
  1868. * Miscellaneous exports from the platform-specific code.
  1869. *
  1870. * filename_serialise and filename_deserialise have the same semantics
  1871. * as fontspec_serialise and fontspec_deserialise above.
  1872. */
  1873. Filename *filename_from_str(const char *string);
  1874. const char *filename_to_str(const Filename *fn);
  1875. bool filename_equal(const Filename *f1, const Filename *f2);
  1876. bool filename_is_null(const Filename *fn);
  1877. Filename *filename_copy(const Filename *fn);
  1878. void filename_free(Filename *fn);
  1879. void filename_serialise(BinarySink *bs, const Filename *f);
  1880. Filename *filename_deserialise(BinarySource *src);
  1881. char *get_username(void); /* return value needs freeing */
  1882. char *get_random_data(int bytes, const char *device); /* used in cmdgen.c */
  1883. char filename_char_sanitise(char c); /* rewrite special pathname chars */
  1884. bool open_for_write_would_lose_data(const Filename *fn);
  1885. /*
  1886. * Exports and imports from timing.c.
  1887. *
  1888. * schedule_timer() asks the front end to schedule a callback to a
  1889. * timer function in a given number of ticks. The returned value is
  1890. * the time (in ticks since an arbitrary offset) at which the
  1891. * callback can be expected. This value will also be passed as the
  1892. * `now' parameter to the callback function. Hence, you can (for
  1893. * example) schedule an event at a particular time by calling
  1894. * schedule_timer() and storing the return value in your context
  1895. * structure as the time when that event is due. The first time a
  1896. * callback function gives you that value or more as `now', you do
  1897. * the thing.
  1898. *
  1899. * expire_timer_context() drops all current timers associated with
  1900. * a given value of ctx (for when you're about to free ctx).
  1901. *
  1902. * run_timers() is called from the front end when it has reason to
  1903. * think some timers have reached their moment, or when it simply
  1904. * needs to know how long to wait next. We pass it the time we
  1905. * think it is. It returns true and places the time when the next
  1906. * timer needs to go off in `next', or alternatively it returns
  1907. * false if there are no timers at all pending.
  1908. *
  1909. * timer_change_notify() must be supplied by the front end; it
  1910. * notifies the front end that a new timer has been added to the
  1911. * list which is sooner than any existing ones. It provides the
  1912. * time when that timer needs to go off.
  1913. *
  1914. * *** FRONT END IMPLEMENTORS NOTE:
  1915. *
  1916. * There's an important subtlety in the front-end implementation of
  1917. * the timer interface. When a front end is given a `next' value,
  1918. * either returned from run_timers() or via timer_change_notify(),
  1919. * it should ensure that it really passes _that value_ as the `now'
  1920. * parameter to its next run_timers call. It should _not_ simply
  1921. * call GETTICKCOUNT() to get the `now' parameter when invoking
  1922. * run_timers().
  1923. *
  1924. * The reason for this is that an OS's system clock might not agree
  1925. * exactly with the timing mechanisms it supplies to wait for a
  1926. * given interval. I'll illustrate this by the simple example of
  1927. * Unix Plink, which uses timeouts to poll() in a way which for
  1928. * these purposes can simply be considered to be a wait() function.
  1929. * Suppose, for the sake of argument, that this wait() function
  1930. * tends to return early by 1%. Then a possible sequence of actions
  1931. * is:
  1932. *
  1933. * - run_timers() tells the front end that the next timer firing
  1934. * is 10000ms from now.
  1935. * - Front end calls wait(10000ms), but according to
  1936. * GETTICKCOUNT() it has only waited for 9900ms.
  1937. * - Front end calls run_timers() again, passing time T-100ms as
  1938. * `now'.
  1939. * - run_timers() does nothing, and says the next timer firing is
  1940. * still 100ms from now.
  1941. * - Front end calls wait(100ms), which only waits for 99ms.
  1942. * - Front end calls run_timers() yet again, passing time T-1ms.
  1943. * - run_timers() says there's still 1ms to wait.
  1944. * - Front end calls wait(1ms).
  1945. *
  1946. * If you're _lucky_ at this point, wait(1ms) will actually wait
  1947. * for 1ms and you'll only have woken the program up three times.
  1948. * If you're unlucky, wait(1ms) might do nothing at all due to
  1949. * being below some minimum threshold, and you might find your
  1950. * program spends the whole of the last millisecond tight-looping
  1951. * between wait() and run_timers().
  1952. *
  1953. * Instead, what you should do is to _save_ the precise `next'
  1954. * value provided by run_timers() or via timer_change_notify(), and
  1955. * use that precise value as the input to the next run_timers()
  1956. * call. So:
  1957. *
  1958. * - run_timers() tells the front end that the next timer firing
  1959. * is at time T, 10000ms from now.
  1960. * - Front end calls wait(10000ms).
  1961. * - Front end then immediately calls run_timers() and passes it
  1962. * time T, without stopping to check GETTICKCOUNT() at all.
  1963. *
  1964. * This guarantees that the program wakes up only as many times as
  1965. * there are actual timer actions to be taken, and that the timing
  1966. * mechanism will never send it into a tight loop.
  1967. *
  1968. * (It does also mean that the timer action in the above example
  1969. * will occur 100ms early, but this is not generally critical. And
  1970. * the hypothetical 1% error in wait() will be partially corrected
  1971. * for anyway when, _after_ run_timers() returns, you call
  1972. * GETTICKCOUNT() and compare the result with the returned `next'
  1973. * value to find out how long you have to make your next wait().)
  1974. */
  1975. typedef void (*timer_fn_t)(void *ctx, unsigned long now);
  1976. unsigned long schedule_timer(int ticks, timer_fn_t fn, void *ctx);
  1977. void expire_timer_context(void *ctx);
  1978. bool run_timers(unsigned long now, unsigned long *next);
  1979. void timer_change_notify(unsigned long next);
  1980. unsigned long timing_last_clock(void);
  1981. /*
  1982. * Exports from callback.c.
  1983. *
  1984. * This provides a method of queuing function calls to be run at the
  1985. * earliest convenience from the top-level event loop. Use it if
  1986. * you're deep in a nested chain of calls and want to trigger an
  1987. * action which will probably lead to your function being re-entered
  1988. * recursively if you just call the initiating function the normal
  1989. * way.
  1990. *
  1991. * Most front ends run the queued callbacks by simply calling
  1992. * run_toplevel_callbacks() after handling each event in their
  1993. * top-level event loop. However, if a front end doesn't have control
  1994. * over its own event loop (e.g. because it's using GTK) then it can
  1995. * instead request notifications when a callback is available, so that
  1996. * it knows to ask its delegate event loop to do the same thing. Also,
  1997. * if a front end needs to know whether a callback is pending without
  1998. * actually running it (e.g. so as to put a zero timeout on a poll()
  1999. * call) then it can call toplevel_callback_pending(), which will
  2000. * return true if at least one callback is in the queue.
  2001. *
  2002. * run_toplevel_callbacks() returns true if it ran any actual code.
  2003. * This can be used as a means of speculatively terminating a poll
  2004. * loop, as in PSFTP, for example - if a callback has run then perhaps
  2005. * it might have done whatever the loop's caller was waiting for.
  2006. */
  2007. typedef void (*toplevel_callback_fn_t)(void *ctx);
  2008. #ifdef MPEXT
  2009. typedef struct callback callback;
  2010. struct IdempotentCallback;
  2011. typedef struct PacketQueueNode PacketQueueNode;
  2012. struct callback_set {
  2013. struct callback *cbcurr, *cbhead, *cbtail;
  2014. IdempotentCallback * ic_pktin_free;
  2015. PacketQueueNode * pktin_freeq_head;
  2016. };
  2017. #define CALLBACK_SET_ONLY struct callback_set * callback_set_v
  2018. #define CALLBACK_SET CALLBACK_SET_ONLY,
  2019. #else
  2020. #define CALLBACK_SET_ONLY void
  2021. #define CALLBACK_SET
  2022. #endif
  2023. void queue_toplevel_callback(CALLBACK_SET toplevel_callback_fn_t fn, void *ctx);
  2024. bool run_toplevel_callbacks(CALLBACK_SET_ONLY);
  2025. bool toplevel_callback_pending(CALLBACK_SET_ONLY);
  2026. bool is_idempotent_callback_pending(CALLBACK_SET struct IdempotentCallback *ic); // WINSCP
  2027. struct callback_set * get_callback_set(Plug * plug);
  2028. struct callback_set * get_seat_callback_set(Seat * seat);
  2029. void delete_callbacks_for_context(CALLBACK_SET void *ctx);
  2030. LogPolicy *log_get_logpolicy(LogContext *ctx); // WINSCP
  2031. Seat * get_log_seat(LogContext * lp); // WINSCP
  2032. struct callback_set * get_log_callback_set(LogContext * lp); // WINSCP
  2033. /*
  2034. * Another facility in callback.c deals with 'idempotent' callbacks,
  2035. * defined as those which never need to be scheduled again if they are
  2036. * already scheduled and have not yet run. (An example would be one
  2037. * which, when called, empties a queue of data completely: when data
  2038. * is added to the queue, you must ensure a run of the queue-consuming
  2039. * function has been scheduled, but if one is already pending, you
  2040. * don't need to schedule a second one.)
  2041. */
  2042. struct IdempotentCallback {
  2043. toplevel_callback_fn_t fn;
  2044. void *ctx;
  2045. bool queued;
  2046. struct callback_set * set;
  2047. };
  2048. void queue_idempotent_callback(struct IdempotentCallback *ic);
  2049. #ifndef MPEXT
  2050. typedef void (*toplevel_callback_notify_fn_t)(void *ctx);
  2051. void request_callback_notifications(toplevel_callback_notify_fn_t notify,
  2052. void *ctx);
  2053. #endif
  2054. /*
  2055. * Define no-op macros for the jump list functions, on platforms that
  2056. * don't support them. (This is a bit of a hack, and it'd be nicer to
  2057. * localise even the calls to those functions into the Windows front
  2058. * end, but it'll do for the moment.)
  2059. */
  2060. #ifndef JUMPLIST_SUPPORTED
  2061. #define add_session_to_jumplist(x) ((void)0)
  2062. #define remove_session_from_jumplist(x) ((void)0)
  2063. #endif
  2064. /* SURROGATE PAIR */
  2065. #ifndef HIGH_SURROGATE_START /* in some toolchains <winnls.h> defines these */
  2066. #define HIGH_SURROGATE_START 0xd800
  2067. #define HIGH_SURROGATE_END 0xdbff
  2068. #define LOW_SURROGATE_START 0xdc00
  2069. #define LOW_SURROGATE_END 0xdfff
  2070. #endif
  2071. /* These macros exist in the Windows API, so the environment may
  2072. * provide them. If not, define them in terms of the above. */
  2073. #ifndef IS_HIGH_SURROGATE
  2074. #define IS_HIGH_SURROGATE(wch) (((wch) >= HIGH_SURROGATE_START) && \
  2075. ((wch) <= HIGH_SURROGATE_END))
  2076. #define IS_LOW_SURROGATE(wch) (((wch) >= LOW_SURROGATE_START) && \
  2077. ((wch) <= LOW_SURROGATE_END))
  2078. #define IS_SURROGATE_PAIR(hs, ls) (IS_HIGH_SURROGATE(hs) && \
  2079. IS_LOW_SURROGATE(ls))
  2080. #endif
  2081. #define IS_SURROGATE(wch) (((wch) >= HIGH_SURROGATE_START) && \
  2082. ((wch) <= LOW_SURROGATE_END))
  2083. #define HIGH_SURROGATE_OF(codept) \
  2084. (HIGH_SURROGATE_START + (((codept) - 0x10000) >> 10))
  2085. #define LOW_SURROGATE_OF(codept) \
  2086. (LOW_SURROGATE_START + (((codept) - 0x10000) & 0x3FF))
  2087. #define FROM_SURROGATES(wch1, wch2) \
  2088. (0x10000 + (((wch1) & 0x3FF) << 10) + ((wch2) & 0x3FF))
  2089. #ifdef WINSCP
  2090. extern CRITICAL_SECTION putty_section;
  2091. void putty_initialize();
  2092. void putty_finalize();
  2093. void pktin_free_queue_callback(void *vctx);
  2094. #define WINSCP_PUTTY_SECTION_ENTER EnterCriticalSection(&putty_section);
  2095. #define WINSCP_PUTTY_SECTION_LEAVE LeaveCriticalSection(&putty_section);
  2096. #else
  2097. #define WINSCP_PUTTY_SECTION_ENTER
  2098. #define WINSCP_PUTTY_SECTION_LEAVE
  2099. #endif
  2100. #ifdef MPEXT
  2101. // To mark carefully selected messages from PuTTY code as UTF-8.
  2102. // Only for messages that are certain not to ever get ansi-encoded component,
  2103. // but known to get UTF-8 encoded component (currently private key path only)
  2104. #define WINSCP_BOM "\xEF\xBB\xBF"
  2105. #endif
  2106. #endif