putty.h 112 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815
  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. * Declared before including platform.h, because that will refer to it
  7. *
  8. * An enum for different types of file that a GUI file requester might
  9. * focus on. (Our requesters never _insist_ on a particular file type
  10. * or extension - there's always an escape hatch to select any file
  11. * you want - but the default can be configured.)
  12. */
  13. typedef enum {
  14. FILTER_ALL_FILES, /* no particular focus */
  15. FILTER_KEY_FILES, /* .ppk */
  16. FILTER_DYNLIB_FILES, /* whatever the host platform uses as shared libs */
  17. FILTER_SOUND_FILES, /* whatever kind of sound file we can use as bell */
  18. } FilereqFilter;
  19. #include "defs.h"
  20. #include "platform.h"
  21. #include "network.h"
  22. #include "misc.h"
  23. #include "marshal.h"
  24. /*
  25. * We express various time intervals in unsigned long minutes, but may need to
  26. * clip some values so that the resulting number of ticks does not overflow an
  27. * integer value.
  28. */
  29. #define MAX_TICK_MINS (INT_MAX / (60 * TICKSPERSEC))
  30. /*
  31. * Fingerprints of the current and previous PGP master keys, to
  32. * establish a trust path between an executable and other files.
  33. */
  34. #define PGP_MASTER_KEY_YEAR "2023"
  35. #define PGP_MASTER_KEY_DETAILS "RSA, 4096-bit"
  36. #define PGP_MASTER_KEY_FP \
  37. "28D4 7C46 55E7 65A6 D827 AC66 B15D 9EFC 216B 06A1"
  38. #define PGP_PREV_MASTER_KEY_YEAR "2021"
  39. #define PGP_PREV_MASTER_KEY_DETAILS "RSA, 3072-bit"
  40. #define PGP_PREV_MASTER_KEY_FP \
  41. "A872 D42F 1660 890F 0E05 223E DD43 55EA AC11 19DE"
  42. /*
  43. * Definitions of three separate indexing schemes for colour palette
  44. * entries.
  45. *
  46. * Why three? Because history, sorry.
  47. *
  48. * Two of the colour indexings are used in escape sequences. The
  49. * Linux-console style OSC P sequences for setting the palette use an
  50. * indexing in which the eight standard ANSI SGR colours come first,
  51. * then their bold versions, and then six extra colours for default
  52. * fg/bg and the terminal cursor. And the xterm OSC 4 sequences for
  53. * querying the palette use a related indexing in which the six extra
  54. * colours are pushed up to indices 256 and onwards, with the previous
  55. * 16 being the first part of the xterm 256-colour space, and 240
  56. * additional terminal-accessible colours inserted in the middle.
  57. *
  58. * The third indexing is the order that the colours appear in the
  59. * PuTTY configuration panel, and also the order in which they're
  60. * described in the saved session files. This order specifies the same
  61. * set of colours as the OSC P encoding, but in a different order,
  62. * with the default fg/bg colours (which users are most likely to want
  63. * to reconfigure) at the start, and the ANSI SGR colours coming
  64. * later.
  65. *
  66. * So all three indices really are needed, because all three appear in
  67. * protocols or file formats outside the PuTTY binary. (Changing the
  68. * saved-session encoding would have a backwards-compatibility impact;
  69. * also, if we ever do, it would be better to replace the numeric
  70. * indices with descriptive keywords.)
  71. *
  72. * Since the OSC 4 encoding contains the full set of colours used in
  73. * the terminal display, that's the encoding used by front ends to
  74. * store any actual data associated with their palette entries. So the
  75. * TermWin palette_set and palette_get_overrides methods use that
  76. * encoding, and so does the bitwise encoding of attribute words used
  77. * in terminal redraw operations.
  78. *
  79. * The Conf encoding, of course, is used by config.c and settings.c.
  80. *
  81. * The aim is that those two sections of the code should never need to
  82. * come directly into contact, and the only module that should have to
  83. * deal directly with the mapping between these colour encodings - or
  84. * to deal _at all_ with the intermediate OSC P encoding - is
  85. * terminal.c itself.
  86. */
  87. #define CONF_NCOLOURS 22 /* 16 + 6 special ones */
  88. #define OSCP_NCOLOURS 22 /* same as CONF, but different order */
  89. #define OSC4_NCOLOURS 262 /* 256 + the same 6 special ones */
  90. /* The list macro for the conf colours also gives the textual names
  91. * used in the GUI configurer */
  92. #define CONF_COLOUR_LIST(X) \
  93. X(fg, "Default Foreground") \
  94. X(fg_bold, "Default Bold Foreground") \
  95. X(bg, "Default Background") \
  96. X(bg_bold, "Default Bold Background") \
  97. X(cursor_fg, "Cursor Text") \
  98. X(cursor_bg, "Cursor Colour") \
  99. X(black, "ANSI Black") \
  100. X(black_bold, "ANSI Black Bold") \
  101. X(red, "ANSI Red") \
  102. X(red_bold, "ANSI Red Bold") \
  103. X(green, "ANSI Green") \
  104. X(green_bold, "ANSI Green Bold") \
  105. X(yellow, "ANSI Yellow") \
  106. X(yellow_bold, "ANSI Yellow Bold") \
  107. X(blue, "ANSI Blue") \
  108. X(blue_bold, "ANSI Blue Bold") \
  109. X(magenta, "ANSI Magenta") \
  110. X(magenta_bold, "ANSI Magenta Bold") \
  111. X(cyan, "ANSI Cyan") \
  112. X(cyan_bold, "ANSI Cyan Bold") \
  113. X(white, "ANSI White") \
  114. X(white_bold, "ANSI White Bold") \
  115. /* end of list */
  116. #define OSCP_COLOUR_LIST(X) \
  117. X(black) \
  118. X(red) \
  119. X(green) \
  120. X(yellow) \
  121. X(blue) \
  122. X(magenta) \
  123. X(cyan) \
  124. X(white) \
  125. X(black_bold) \
  126. X(red_bold) \
  127. X(green_bold) \
  128. X(yellow_bold) \
  129. X(blue_bold) \
  130. X(magenta_bold) \
  131. X(cyan_bold) \
  132. X(white_bold) \
  133. /*
  134. * In the OSC 4 indexing, this is where the extra 240 colours go.
  135. * They consist of:
  136. *
  137. * - 216 colours forming a 6x6x6 cube, with R the most
  138. * significant colour and G the least. In other words, these
  139. * occupy the space of indices 16 <= i < 232, with each
  140. * individual colour found as i = 16 + 36*r + 6*g + b, for all
  141. * 0 <= r,g,b <= 5.
  142. *
  143. * - The remaining indices, 232 <= i < 256, consist of a uniform
  144. * series of grey shades running between black and white (but
  145. * not including either, since actual black and white are
  146. * already provided in the previous colour cube).
  147. *
  148. * After that, we have the remaining 6 special colours:
  149. */ \
  150. X(fg) \
  151. X(fg_bold) \
  152. X(bg) \
  153. X(bg_bold) \
  154. X(cursor_fg) \
  155. X(cursor_bg) \
  156. /* end of list */
  157. /* Enumerations of the colour lists. These are available everywhere in
  158. * the code. The OSC P encoding shouldn't be used outside terminal.c,
  159. * but the easiest way to define the OSC 4 enum is to have the OSC P
  160. * one available to compute with. */
  161. enum {
  162. #define ENUM_DECL(id,name) CONF_COLOUR_##id,
  163. CONF_COLOUR_LIST(ENUM_DECL)
  164. #undef ENUM_DECL
  165. };
  166. enum {
  167. #define ENUM_DECL(id) OSCP_COLOUR_##id,
  168. OSCP_COLOUR_LIST(ENUM_DECL)
  169. #undef ENUM_DECL
  170. };
  171. enum {
  172. #define ENUM_DECL(id) OSC4_COLOUR_##id = \
  173. OSCP_COLOUR_##id + (OSCP_COLOUR_##id >= 16 ? 240 : 0),
  174. OSCP_COLOUR_LIST(ENUM_DECL)
  175. #undef ENUM_DECL
  176. };
  177. /* Mapping tables defined in terminal.c */
  178. extern const int colour_indices_conf_to_oscp[CONF_NCOLOURS];
  179. extern const int colour_indices_conf_to_osc4[CONF_NCOLOURS];
  180. extern const int colour_indices_oscp_to_osc4[OSCP_NCOLOURS];
  181. /* Three attribute types:
  182. * The ATTRs (normal attributes) are stored with the characters in
  183. * the main display arrays
  184. *
  185. * The TATTRs (temporary attributes) are generated on the fly, they
  186. * can overlap with characters but not with normal attributes.
  187. *
  188. * The LATTRs (line attributes) are an entirely disjoint space of
  189. * flags.
  190. *
  191. * The DATTRs (display attributes) are internal to terminal.c (but
  192. * defined here because their values have to match the others
  193. * here); they reuse the TATTR_* space but are always masked off
  194. * before sending to the front end.
  195. *
  196. * ATTR_INVALID is an illegal colour combination.
  197. */
  198. #define TATTR_ACTCURS 0x40000000UL /* active cursor (block) */
  199. #define TATTR_PASCURS 0x20000000UL /* passive cursor (box) */
  200. #define TATTR_RIGHTCURS 0x10000000UL /* cursor-on-RHS */
  201. #define TATTR_COMBINING 0x80000000UL /* combining characters */
  202. #define DATTR_STARTRUN 0x80000000UL /* start of redraw run */
  203. #define TDATTR_MASK 0xF0000000UL
  204. #define TATTR_MASK (TDATTR_MASK)
  205. #define DATTR_MASK (TDATTR_MASK)
  206. #define LATTR_NORM 0x00000000UL
  207. #define LATTR_WIDE 0x00000001UL
  208. #define LATTR_TOP 0x00000002UL
  209. #define LATTR_BOT 0x00000003UL
  210. #define LATTR_MODE 0x00000003UL
  211. #define LATTR_WRAPPED 0x00000010UL /* this line wraps to next */
  212. #define LATTR_WRAPPED2 0x00000020UL /* with WRAPPED: CJK wide character
  213. wrapped to next line, so last
  214. single-width cell is empty */
  215. #define ATTR_INVALID 0x03FFFFU
  216. /* Use the DC00 page for direct to font. */
  217. #define CSET_OEMCP 0x0000DC00UL /* OEM Codepage DTF */
  218. #define CSET_ACP 0x0000DD00UL /* Ansi Codepage DTF */
  219. /* These are internal use overlapping with the UTF-16 surrogates */
  220. #define CSET_ASCII 0x0000D800UL /* normal ASCII charset ESC ( B */
  221. #define CSET_LINEDRW 0x0000D900UL /* line drawing charset ESC ( 0 */
  222. #define CSET_SCOACS 0x0000DA00UL /* SCO Alternate charset */
  223. #define CSET_GBCHR 0x0000DB00UL /* UK variant charset ESC ( A */
  224. #define CSET_MASK 0xFFFFFF00UL /* Character set mask */
  225. #define DIRECT_CHAR(c) ((c&0xFFFFFC00)==0xD800)
  226. #define DIRECT_FONT(c) ((c&0xFFFFFE00)==0xDC00)
  227. #define UCSERR (CSET_LINEDRW|'a') /* UCS Format error character. */
  228. /*
  229. * UCSWIDE is a special value used in the terminal data to signify
  230. * the character cell containing the right-hand half of a CJK wide
  231. * character. We use 0xDFFF because it's part of the surrogate
  232. * range and hence won't be used for anything else (it's impossible
  233. * to input it via UTF-8 because our UTF-8 decoder correctly
  234. * rejects surrogates).
  235. */
  236. #define UCSWIDE 0xDFFF
  237. #define ATTR_NARROW 0x0800000U
  238. #define ATTR_WIDE 0x0400000U
  239. #define ATTR_BOLD 0x0040000U
  240. #define ATTR_UNDER 0x0080000U
  241. #define ATTR_REVERSE 0x0100000U
  242. #define ATTR_BLINK 0x0200000U
  243. #define ATTR_FGMASK 0x00001FFU /* stores a colour in OSC 4 indexing */
  244. #define ATTR_BGMASK 0x003FE00U /* stores a colour in OSC 4 indexing */
  245. #define ATTR_COLOURS 0x003FFFFU
  246. #define ATTR_DIM 0x1000000U
  247. #define ATTR_STRIKE 0x2000000U
  248. #define ATTR_FGSHIFT 0
  249. #define ATTR_BGSHIFT 9
  250. #define ATTR_DEFFG (OSC4_COLOUR_fg << ATTR_FGSHIFT)
  251. #define ATTR_DEFBG (OSC4_COLOUR_bg << ATTR_BGSHIFT)
  252. #define ATTR_DEFAULT (ATTR_DEFFG | ATTR_DEFBG)
  253. struct sesslist {
  254. int nsessions;
  255. const char **sessions;
  256. char *buffer; /* so memory can be freed later */
  257. };
  258. struct unicode_data {
  259. bool dbcs_screenfont;
  260. int font_codepage;
  261. int line_codepage;
  262. wchar_t unitab_scoacs[256];
  263. wchar_t unitab_line[256];
  264. wchar_t unitab_font[256];
  265. wchar_t unitab_xterm[256];
  266. wchar_t unitab_oemcp[256];
  267. unsigned char unitab_ctrl[256];
  268. };
  269. #define LGXF_OVR 1 /* existing logfile overwrite */
  270. #define LGXF_APN 0 /* existing logfile append */
  271. #define LGXF_ASK -1 /* existing logfile ask */
  272. #define LGTYP_NONE 0 /* logmode: no logging */
  273. #define LGTYP_ASCII 1 /* logmode: pure ascii */
  274. #define LGTYP_DEBUG 2 /* logmode: all chars of traffic */
  275. #define LGTYP_PACKETS 3 /* logmode: SSH data packets */
  276. #define LGTYP_SSHRAW 4 /* logmode: SSH raw data */
  277. /* Platform-generic function to set up a struct unicode_data. This is
  278. * only likely to be useful to test programs; real clients will want
  279. * to use the more flexible per-platform setup functions. */
  280. void init_ucs_generic(Conf *conf, struct unicode_data *ucsdata);
  281. /*
  282. * Enumeration of 'special commands' that can be sent during a
  283. * session, separately from the byte stream of ordinary session data.
  284. */
  285. typedef enum {
  286. /* The list of enum constants is defined in a separate header so
  287. * they can be reused in other contexts */
  288. #define SPECIAL(x) SS_ ## x,
  289. #include "specials.h"
  290. #undef SPECIAL
  291. } SessionSpecialCode;
  292. /*
  293. * The structure type returned from backend_get_specials.
  294. */
  295. struct SessionSpecial {
  296. const char *name;
  297. SessionSpecialCode code;
  298. int arg;
  299. };
  300. /* Needed by both ssh/channel.h and ssh/ppl.h */
  301. typedef void (*add_special_fn_t)(
  302. void *ctx, const char *text, SessionSpecialCode code, int arg);
  303. typedef enum {
  304. MBT_NOTHING,
  305. MBT_LEFT, MBT_MIDDLE, MBT_RIGHT, /* `raw' button designations */
  306. MBT_SELECT, MBT_EXTEND, MBT_PASTE, /* `cooked' button designations */
  307. MBT_WHEEL_UP, MBT_WHEEL_DOWN, /* vertical mouse wheel */
  308. MBT_WHEEL_LEFT, MBT_WHEEL_RIGHT /* horizontal mouse wheel */
  309. } Mouse_Button;
  310. typedef enum {
  311. MA_NOTHING, MA_CLICK, MA_2CLK, MA_3CLK, MA_DRAG, MA_RELEASE, MA_MOVE
  312. } Mouse_Action;
  313. /* Keyboard modifiers -- keys the user is actually holding down */
  314. #define PKM_SHIFT 0x01
  315. #define PKM_CONTROL 0x02
  316. #define PKM_META 0x04
  317. #define PKM_ALT 0x08
  318. /* Keyboard flags that aren't really modifiers */
  319. #define PKF_CAPSLOCK 0x10
  320. #define PKF_NUMLOCK 0x20
  321. #define PKF_REPEAT 0x40
  322. /* Stand-alone keysyms for function keys */
  323. typedef enum {
  324. PK_NULL, /* No symbol for this key */
  325. /* Main keypad keys */
  326. PK_ESCAPE, PK_TAB, PK_BACKSPACE, PK_RETURN, PK_COMPOSE,
  327. /* Editing keys */
  328. PK_HOME, PK_INSERT, PK_DELETE, PK_END, PK_PAGEUP, PK_PAGEDOWN,
  329. /* Cursor keys */
  330. PK_UP, PK_DOWN, PK_RIGHT, PK_LEFT, PK_REST,
  331. /* Numeric keypad */ /* Real one looks like: */
  332. PK_PF1, PK_PF2, PK_PF3, PK_PF4, /* PF1 PF2 PF3 PF4 */
  333. PK_KPCOMMA, PK_KPMINUS, PK_KPDECIMAL, /* 7 8 9 - */
  334. PK_KP0, PK_KP1, PK_KP2, PK_KP3, PK_KP4, /* 4 5 6 , */
  335. PK_KP5, PK_KP6, PK_KP7, PK_KP8, PK_KP9, /* 1 2 3 en- */
  336. PK_KPBIGPLUS, PK_KPENTER, /* 0 . ter */
  337. /* Top row */
  338. PK_F1, PK_F2, PK_F3, PK_F4, PK_F5,
  339. PK_F6, PK_F7, PK_F8, PK_F9, PK_F10,
  340. PK_F11, PK_F12, PK_F13, PK_F14, PK_F15,
  341. PK_F16, PK_F17, PK_F18, PK_F19, PK_F20,
  342. PK_PAUSE
  343. } Key_Sym;
  344. #define PK_ISEDITING(k) ((k) >= PK_HOME && (k) <= PK_PAGEDOWN)
  345. #define PK_ISCURSOR(k) ((k) >= PK_UP && (k) <= PK_REST)
  346. #define PK_ISKEYPAD(k) ((k) >= PK_PF1 && (k) <= PK_KPENTER)
  347. #define PK_ISFKEY(k) ((k) >= PK_F1 && (k) <= PK_F20)
  348. enum {
  349. VT_XWINDOWS, VT_OEMANSI, VT_OEMONLY, VT_POORMAN, VT_UNICODE
  350. };
  351. enum {
  352. /*
  353. * SSH-2 key exchange algorithms
  354. */
  355. KEX_WARN,
  356. KEX_DHGROUP1,
  357. KEX_DHGROUP14,
  358. KEX_DHGROUP15,
  359. KEX_DHGROUP16,
  360. KEX_DHGROUP17,
  361. KEX_DHGROUP18,
  362. KEX_DHGEX,
  363. KEX_RSA,
  364. KEX_ECDH,
  365. KEX_NTRU_HYBRID,
  366. KEX_MLKEM_25519_HYBRID,
  367. KEX_MLKEM_NIST_HYBRID,
  368. KEX_MAX
  369. };
  370. enum {
  371. /*
  372. * SSH-2 host key algorithms
  373. */
  374. HK_WARN,
  375. HK_RSA,
  376. HK_DSA,
  377. HK_ECDSA,
  378. HK_ED25519,
  379. HK_ED448,
  380. HK_MAX
  381. };
  382. enum {
  383. /*
  384. * SSH ciphers (both SSH-1 and SSH-2)
  385. */
  386. CIPHER_WARN, /* pseudo 'cipher' */
  387. CIPHER_3DES,
  388. CIPHER_BLOWFISH,
  389. CIPHER_AES, /* (SSH-2 only) */
  390. CIPHER_DES,
  391. CIPHER_ARCFOUR,
  392. CIPHER_CHACHA20,
  393. CIPHER_AESGCM,
  394. CIPHER_MAX /* no. ciphers (inc warn) */
  395. };
  396. enum TriState {
  397. /*
  398. * Several different bits of the PuTTY configuration seem to be
  399. * three-way settings whose values are `always yes', `always
  400. * no', and `decide by some more complex automated means'. This
  401. * is true of line discipline options (local echo and line
  402. * editing), proxy DNS, proxy terminal logging, Close On Exit, and
  403. * SSH server bug workarounds. Accordingly I supply a single enum
  404. * here to deal with them all.
  405. */
  406. FORCE_ON, FORCE_OFF, AUTO
  407. };
  408. enum {
  409. /*
  410. * Proxy types.
  411. */
  412. PROXY_NONE, PROXY_SOCKS4, PROXY_SOCKS5,
  413. PROXY_HTTP, PROXY_TELNET, PROXY_CMD, PROXY_SSH_TCPIP,
  414. PROXY_SSH_EXEC, PROXY_SSH_SUBSYSTEM,
  415. PROXY_FUZZ
  416. };
  417. enum {
  418. /*
  419. * Line discipline options which the backend might try to control.
  420. */
  421. LD_EDIT, /* local line editing */
  422. LD_ECHO, /* local echo */
  423. LD_N_OPTIONS
  424. };
  425. enum {
  426. /* Actions on remote window title query */
  427. TITLE_NONE, TITLE_EMPTY, TITLE_REAL
  428. };
  429. enum {
  430. /* SUPDUP character set options */
  431. SUPDUP_CHARSET_ASCII, SUPDUP_CHARSET_ITS, SUPDUP_CHARSET_WAITS
  432. };
  433. enum {
  434. /* Protocol back ends. (CONF_protocol) */
  435. PROT_RAW, PROT_TELNET, PROT_RLOGIN, PROT_SSH, PROT_SSHCONN,
  436. /* PROT_SERIAL is supported on a subset of platforms, but it doesn't
  437. * hurt to define it globally. */
  438. PROT_SERIAL,
  439. /* PROT_SUPDUP is the historical RFC 734 protocol. */
  440. PROT_SUPDUP,
  441. PROTOCOL_LIMIT, /* upper bound on number of protocols */
  442. };
  443. enum {
  444. /* Bell settings (CONF_beep) */
  445. BELL_DISABLED, BELL_DEFAULT, BELL_VISUAL, BELL_WAVEFILE, BELL_PCSPEAKER
  446. };
  447. enum {
  448. /* Taskbar flashing indication on bell (CONF_beep_ind) */
  449. B_IND_DISABLED, B_IND_FLASH, B_IND_STEADY
  450. };
  451. enum {
  452. /* Resize actions (CONF_resize_action) */
  453. RESIZE_TERM, RESIZE_DISABLED, RESIZE_FONT, RESIZE_EITHER
  454. };
  455. enum {
  456. /* Mouse-button assignments */
  457. MOUSE_COMPROMISE, /* xterm-ish but with paste on RB in case no MB exists */
  458. MOUSE_XTERM, /* xterm-style: MB pastes, RB extends selection */
  459. MOUSE_WINDOWS /* Windows-style: RB brings up menu. MB still extends. */
  460. };
  461. enum {
  462. /* Function key types (CONF_funky_type) */
  463. FUNKY_TILDE,
  464. FUNKY_LINUX,
  465. FUNKY_XTERM,
  466. FUNKY_VT400,
  467. FUNKY_VT100P,
  468. FUNKY_SCO,
  469. FUNKY_XTERM_216
  470. };
  471. enum {
  472. /* Shifted arrow key types (CONF_sharrow_type) */
  473. SHARROW_APPLICATION, /* Ctrl flips between ESC O A and ESC [ A */
  474. SHARROW_BITMAP /* ESC [ 1 ; n A, where n = 1 + bitmap of CAS */
  475. };
  476. enum {
  477. FQ_DEFAULT, FQ_ANTIALIASED, FQ_NONANTIALIASED, FQ_CLEARTYPE
  478. };
  479. enum {
  480. CURSOR_BLOCK, CURSOR_UNDERLINE, CURSOR_VERTICAL_LINE
  481. };
  482. enum {
  483. /* these are really bit flags */
  484. BOLD_STYLE_FONT = 1,
  485. BOLD_STYLE_COLOUR = 2,
  486. };
  487. enum {
  488. SER_PAR_NONE, SER_PAR_ODD, SER_PAR_EVEN, SER_PAR_MARK, SER_PAR_SPACE
  489. };
  490. enum {
  491. SER_FLOW_NONE, SER_FLOW_XONXOFF, SER_FLOW_RTSCTS, SER_FLOW_DSRDTR
  492. };
  493. /*
  494. * Tables of string <-> enum value mappings used in settings.c.
  495. * Defined here so that backends can export their GSS library tables
  496. * to the cross-platform settings code.
  497. */
  498. struct keyvalwhere {
  499. /*
  500. * Two fields which define a string and enum value to be
  501. * equivalent to each other.
  502. */
  503. const char *s;
  504. int v;
  505. /*
  506. * The next pair of fields are used by gprefs() in settings.c to
  507. * arrange that when it reads a list of strings representing a
  508. * preference list and translates it into the corresponding list
  509. * of integers, strings not appearing in the list are entered in a
  510. * configurable position rather than uniformly at the end.
  511. */
  512. /*
  513. * 'vrel' indicates which other value in the list to place this
  514. * element relative to. It should be a value that has occurred in
  515. * a 'v' field of some other element of the array, or -1 to
  516. * indicate that we simply place relative to one or other end of
  517. * the list.
  518. *
  519. * gprefs will try to process the elements in an order which makes
  520. * this field work (i.e. so that the element referenced has been
  521. * added before processing this one).
  522. */
  523. int vrel;
  524. /*
  525. * 'where' indicates whether to place the new value before or
  526. * after the one referred to by vrel. -1 means before; +1 means
  527. * after.
  528. *
  529. * When vrel is -1, this also implicitly indicates which end of
  530. * the array to use. So vrel=-1, where=-1 means to place _before_
  531. * some end of the list (hence, at the last element); vrel=-1,
  532. * where=+1 means to place _after_ an end (hence, at the first).
  533. */
  534. int where;
  535. };
  536. #ifndef NO_GSSAPI
  537. extern const int ngsslibs;
  538. extern const char *const gsslibnames[]; /* for displaying in configuration */
  539. extern const struct keyvalwhere gsslibkeywords[]; /* for settings.c */
  540. #endif
  541. extern const char *const ttymodes[];
  542. enum {
  543. /*
  544. * Network address types. Used for specifying choice of IPv4/v6
  545. * in config; also used in proxy.c to indicate whether a given
  546. * host name has already been resolved or will be resolved at
  547. * the proxy end.
  548. */
  549. ADDRTYPE_UNSPEC,
  550. ADDRTYPE_IPV4,
  551. ADDRTYPE_IPV6,
  552. ADDRTYPE_LOCAL, /* e.g. Unix domain socket, or Windows named pipe */
  553. ADDRTYPE_NAME /* SockAddr storing an unresolved host name */
  554. };
  555. /* Backend flags */
  556. #define BACKEND_RESIZE_FORBIDDEN 0x01 /* Backend does not allow
  557. resizing terminal */
  558. #define BACKEND_NEEDS_TERMINAL 0x02 /* Backend must have terminal */
  559. #define BACKEND_SUPPORTS_NC_HOST 0x04 /* Backend can honour
  560. CONF_ssh_nc_host */
  561. #define BACKEND_NOTIFIES_SESSION_START 0x08 /* Backend will call
  562. seat_notify_session_started */
  563. /* In (no)sshproxy.c */
  564. extern const bool ssh_proxy_supported;
  565. /*
  566. * This structure type wraps a Seat pointer, in a way that has no
  567. * purpose except to be a different type.
  568. *
  569. * The Seat wrapper functions that present interactive prompts all
  570. * expect one of these in place of their ordinary Seat pointer. You
  571. * get one by calling interactor_announce (defined below), which will
  572. * print a message (if not already done) identifying the Interactor
  573. * that originated the prompt.
  574. *
  575. * This arranges that the C type system itself will check that no call
  576. * to any of those Seat methods has omitted the mandatory call to
  577. * interactor_announce beforehand.
  578. */
  579. struct InteractionReadySeat {
  580. Seat *seat;
  581. };
  582. /*
  583. * The Interactor trait is implemented by anything that is capable of
  584. * presenting interactive prompts or questions to the user during
  585. * network connection setup. Every Backend that ever needs to do this
  586. * is an Interactor, but also, while a Backend is making its initial
  587. * network connection, it may go via network proxy code which is also
  588. * an Interactor and can ask questions of its own.
  589. */
  590. struct Interactor {
  591. const InteractorVtable *vt;
  592. /* The parent Interactor that we are a proxy for, if any. */
  593. Interactor *parent;
  594. /*
  595. * If we're the top-level Interactor (parent==NULL), then this
  596. * field records the last Interactor that actually did anything
  597. * interactive, so that we know when to announce a changeover
  598. * between levels of proxying.
  599. *
  600. * If parent != NULL, this field is not used.
  601. */
  602. Interactor *last_to_talk;
  603. };
  604. struct InteractorVtable {
  605. /*
  606. * Returns a user-facing description of the nature of the network
  607. * connection being made. Used in interactive proxy authentication
  608. * to announce which connection attempt is now in control of the
  609. * Seat.
  610. *
  611. * The idea is not just to be written in natural language, but to
  612. * connect with the user's idea of _why_ they think some
  613. * connection is being made. For example, instead of saying 'TCP
  614. * connection to 123.45.67.89 port 22', you might say 'SSH
  615. * connection to [logical host name for SSH host key purposes]'.
  616. *
  617. * The returned string must be freed by the caller.
  618. */
  619. char *(*description)(Interactor *itr);
  620. /*
  621. * Returns the LogPolicy associated with this Interactor. (A
  622. * Backend can derive this from its logging context; a proxy
  623. * Interactor inherits it from the Interactor for the parent
  624. * network connection.)
  625. */
  626. LogPolicy *(*logpolicy)(Interactor *itr);
  627. /*
  628. * Gets and sets the Seat that this Interactor talks to. When a
  629. * Seat is borrowed and replaced with a TempSeat, this will be the
  630. * mechanism by which that replacement happens.
  631. */
  632. Seat *(*get_seat)(Interactor *itr);
  633. void (*set_seat)(Interactor *itr, Seat *seat);
  634. };
  635. static inline char *interactor_description(Interactor *itr)
  636. { return itr->vt->description(itr); }
  637. static inline LogPolicy *interactor_logpolicy(Interactor *itr)
  638. { return itr->vt->logpolicy(itr); }
  639. static inline Seat *interactor_get_seat(Interactor *itr)
  640. { return itr->vt->get_seat(itr); }
  641. static inline void interactor_set_seat(Interactor *itr, Seat *seat)
  642. { itr->vt->set_seat(itr, seat); }
  643. static inline void interactor_set_child(Interactor *parent, Interactor *child)
  644. { child->parent = parent; }
  645. Seat *interactor_borrow_seat(Interactor *itr);
  646. void interactor_return_seat(Interactor *itr);
  647. InteractionReadySeat interactor_announce(Interactor *itr);
  648. /* Interactors that are Backends will find this helper function useful
  649. * in constructing their description strings */
  650. char *default_description(const BackendVtable *backvt,
  651. const char *host, int port);
  652. /*
  653. * The Backend trait is the top-level one that governs each of the
  654. * user-facing main modes that PuTTY can use to talk to some
  655. * destination: SSH, Telnet, serial port, pty, etc.
  656. */
  657. struct Backend {
  658. const BackendVtable *vt;
  659. /* Many Backends are also Interactors. If this one is, a pointer
  660. * to its Interactor trait lives here. */
  661. Interactor *interactor;
  662. };
  663. struct BackendVtable {
  664. char *(*init) (const BackendVtable *vt, Seat *seat,
  665. Backend **backend_out, LogContext *logctx, Conf *conf,
  666. const char *host, int port, char **realhost,
  667. bool nodelay, bool keepalive);
  668. void (*free) (Backend *be);
  669. /* Pass in a replacement configuration. */
  670. void (*reconfig) (Backend *be, Conf *conf);
  671. void (*send) (Backend *be, const char *buf, size_t len);
  672. /* sendbuffer() returns the current amount of buffered data */
  673. size_t (*sendbuffer) (Backend *be);
  674. void (*size) (Backend *be, int width, int height);
  675. void (*special) (Backend *be, SessionSpecialCode code, int arg);
  676. const SessionSpecial *(*get_specials) (Backend *be);
  677. bool (*connected) (Backend *be);
  678. int (*exitcode) (Backend *be);
  679. /* If back->sendok() returns false, the backend doesn't currently
  680. * want input data, so the frontend should avoid acquiring any if
  681. * possible (passing back-pressure on to its sender).
  682. *
  683. * Policy rule: no backend shall return true from sendok() while
  684. * its network connection attempt is still ongoing. This ensures
  685. * that if making the network connection involves a proxy type
  686. * which wants to interact with the user via the terminal, the
  687. * proxy implementation and the backend itself won't fight over
  688. * who gets the terminal input. */
  689. bool (*sendok) (Backend *be);
  690. bool (*ldisc_option_state) (Backend *be, int);
  691. void (*provide_ldisc) (Backend *be, Ldisc *ldisc);
  692. /* Tells the back end that the front end buffer is clearing. */
  693. void (*unthrottle) (Backend *be, size_t bufsize);
  694. int (*cfg_info) (Backend *be);
  695. /* Only implemented in the SSH protocol: check whether a
  696. * connection-sharing upstream exists for a given configuration. */
  697. bool (*test_for_upstream)(const char *host, int port, Conf *conf);
  698. /* Special-purpose function to return additional information to put
  699. * in a "are you sure you want to close this session" dialog;
  700. * return NULL if no such info, otherwise caller must free.
  701. * Only implemented in the SSH protocol, to warn about downstream
  702. * connections that would be lost if this one were terminated. */
  703. char *(*close_warn_text)(Backend *be);
  704. /* 'id' is a machine-readable name for the backend, used in
  705. * saved-session storage. 'displayname_tc' and 'displayname_lc'
  706. * are human-readable names, one in title-case for config boxes,
  707. * and one in lower-case for use in mid-sentence. */
  708. const char *id, *displayname_tc, *displayname_lc;
  709. int protocol;
  710. int default_port;
  711. unsigned flags;
  712. /* Only relevant for the serial protocol: bit masks of which
  713. * parity and flow control settings are supported. */
  714. unsigned serial_parity_mask, serial_flow_mask;
  715. };
  716. static inline char *backend_init(
  717. const BackendVtable *vt, Seat *seat, Backend **out, LogContext *logctx,
  718. Conf *conf, const char *host, int port, char **rhost, bool nd, bool ka)
  719. { return vt->init(vt, seat, out, logctx, conf, host, port, rhost, nd, ka); }
  720. static inline void backend_free(Backend *be)
  721. { be->vt->free(be); }
  722. static inline void backend_reconfig(Backend *be, Conf *conf)
  723. { be->vt->reconfig(be, conf); }
  724. static inline void backend_send(Backend *be, const char *buf, size_t len)
  725. { be->vt->send(be, buf, len); }
  726. static inline size_t backend_sendbuffer(Backend *be)
  727. { return be->vt->sendbuffer(be); }
  728. static inline void backend_size(Backend *be, int width, int height)
  729. { be->vt->size(be, width, height); }
  730. static inline void backend_special(
  731. Backend *be, SessionSpecialCode code, int arg)
  732. { be->vt->special(be, code, arg); }
  733. static inline const SessionSpecial *backend_get_specials(Backend *be)
  734. { return be->vt->get_specials(be); }
  735. static inline bool backend_connected(Backend *be)
  736. { return be->vt->connected(be); }
  737. static inline int backend_exitcode(Backend *be)
  738. { return be->vt->exitcode(be); }
  739. static inline bool backend_sendok(Backend *be)
  740. { return be->vt->sendok(be); }
  741. static inline bool backend_ldisc_option_state(Backend *be, int state)
  742. { return be->vt->ldisc_option_state(be, state); }
  743. static inline void backend_provide_ldisc(Backend *be, Ldisc *ldisc)
  744. { be->vt->provide_ldisc(be, ldisc); }
  745. static inline void backend_unthrottle(Backend *be, size_t bufsize)
  746. { be->vt->unthrottle(be, bufsize); }
  747. static inline int backend_cfg_info(Backend *be)
  748. { return be->vt->cfg_info(be); }
  749. extern const struct BackendVtable *const backends[];
  750. /*
  751. * In programs with a config UI, only the first few members of
  752. * backends[] will be displayed at the top-level; the others will be
  753. * relegated to a drop-down.
  754. */
  755. extern const size_t n_ui_backends;
  756. /*
  757. * Suggested default protocol provided by the backend link module.
  758. * The application is free to ignore this.
  759. */
  760. extern const int be_default_protocol;
  761. /*
  762. * Name of this particular application, for use in the config box
  763. * and other pieces of text.
  764. */
  765. extern const char *const appname;
  766. /*
  767. * Used by callback.c; declared up here so that prompts_t can use it
  768. */
  769. typedef void (*toplevel_callback_fn_t)(void *ctx);
  770. /* Enum of result types in SeatPromptResult below */
  771. typedef enum SeatPromptResultKind {
  772. /* Answer not yet available at all; either try again later or wait
  773. * for a callback (depending on the request's API) */
  774. SPRK_INCOMPLETE,
  775. /* We're abandoning the connection because the user interactively
  776. * told us to. (Hence, no need to present an error message
  777. * telling the user we're doing that: they already know.) */
  778. SPRK_USER_ABORT,
  779. /* We're abandoning the connection for some other reason (e.g. we
  780. * were unable to present the prompt at all, or a batch-mode
  781. * configuration told us to give the answer no). This may
  782. * ultimately have stemmed from some user configuration, but they
  783. * didn't _tell us right now_ to abandon this connection, so we
  784. * still need to inform them that we've done so. */
  785. SPRK_SW_ABORT,
  786. /* We're proceeding with the connection and have all requested
  787. * information (if any) */
  788. SPRK_OK
  789. } SeatPromptResultKind;
  790. /* Small struct to present the results of interactive requests from
  791. * backend to Seat (see below) */
  792. struct SeatPromptResult {
  793. SeatPromptResultKind kind;
  794. /*
  795. * In the case of SPRK_SW_ABORT, the frontend provides an error
  796. * message to present to the user. But dynamically allocating it
  797. * up front would mean having to make sure it got freed at any
  798. * call site where one of these structs is received (and freed
  799. * _once_ no matter how many times the struct is copied). So
  800. * instead we provide a function that will generate the error
  801. * message into a BinarySink.
  802. */
  803. void (*errfn)(SeatPromptResult, BinarySink *);
  804. /*
  805. * And some fields the error function can use to construct the
  806. * message (holding, e.g. an OS error code).
  807. */
  808. const char *errdata_lit; /* statically allocated, e.g. a string literal */
  809. unsigned errdata_u;
  810. };
  811. /* Helper function to construct the simple versions of these
  812. * structures inline */
  813. static inline SeatPromptResult make_spr_simple(SeatPromptResultKind kind)
  814. {
  815. SeatPromptResult spr;
  816. spr.kind = kind;
  817. spr.errdata_lit = NULL;
  818. return spr;
  819. }
  820. /* Most common constructor function for SPRK_SW_ABORT errors */
  821. SeatPromptResult make_spr_sw_abort_static(const char *);
  822. /* Convenience macros wrapping those constructors in turn */
  823. #define SPR_INCOMPLETE make_spr_simple(SPRK_INCOMPLETE)
  824. #define SPR_USER_ABORT make_spr_simple(SPRK_USER_ABORT)
  825. #define SPR_SW_ABORT(lit) make_spr_sw_abort_static(lit)
  826. #define SPR_OK make_spr_simple(SPRK_OK)
  827. /* Query function that folds both kinds of abort together */
  828. static inline bool spr_is_abort(SeatPromptResult spr)
  829. {
  830. return spr.kind == SPRK_USER_ABORT || spr.kind == SPRK_SW_ABORT;
  831. }
  832. /* Function to return a dynamically allocated copy of the error message */
  833. char *spr_get_error_message(SeatPromptResult spr);
  834. /*
  835. * Mechanism for getting text strings such as usernames and passwords
  836. * from the front-end.
  837. * The fields are mostly modelled after SSH's keyboard-interactive auth.
  838. * FIXME We should probably mandate a character set/encoding (probably UTF-8).
  839. *
  840. * Since many of the pieces of text involved may be chosen by the server,
  841. * the caller must take care to ensure that the server can't spoof locally-
  842. * generated prompts such as key passphrase prompts. Some ground rules:
  843. * - If the front-end needs to truncate a string, it should lop off the
  844. * end.
  845. * - The front-end should filter out any dangerous characters and
  846. * generally not trust the strings. (But \n is required to behave
  847. * vaguely sensibly, at least in `instruction', and ideally in
  848. * `prompt[]' too.)
  849. */
  850. typedef struct {
  851. char *prompt;
  852. bool echo;
  853. strbuf *result;
  854. } prompt_t;
  855. typedef struct prompts_t prompts_t;
  856. struct prompts_t {
  857. /*
  858. * Indicates whether the information entered is to be used locally
  859. * (for instance a key passphrase prompt), or is destined for the wire.
  860. * This is a hint only; the front-end is at liberty not to use this
  861. * information (so the caller should ensure that the supplied text is
  862. * sufficient).
  863. */
  864. bool to_server;
  865. /*
  866. * Indicates whether the prompts originated _at_ the server, so
  867. * that the front end can display some kind of trust sigil that
  868. * distinguishes (say) a legit private-key passphrase prompt from
  869. * a fake one sent by a malicious server.
  870. */
  871. bool from_server;
  872. char *name; /* Short description, perhaps for dialog box title */
  873. bool name_reqd; /* Display of `name' required or optional? */
  874. char *instruction; /* Long description, maybe with embedded newlines */
  875. bool instr_reqd; /* Display of `instruction' required or optional? */
  876. size_t n_prompts; /* May be zero (in which case display the foregoing,
  877. * if any, and return success) */
  878. size_t prompts_size; /* allocated storage capacity for prompts[] */
  879. prompt_t **prompts;
  880. void *data; /* slot for housekeeping data, managed by
  881. * seat_get_userpass_input(); initially NULL */
  882. SeatPromptResult spr; /* some implementations need to cache one of these */
  883. /*
  884. * Set this flag to indicate that the caller has encoded the
  885. * prompts in UTF-8, and expects the responses to be UTF-8 too.
  886. *
  887. * Ideally this flag would be unnecessary because it would always
  888. * be true, but for legacy reasons, we have to switch over a bit
  889. * at a time from the old behaviour, and may never manage to get
  890. * rid of it completely.
  891. */
  892. bool utf8;
  893. /*
  894. * Callback you can fill in to be notified when all the prompts'
  895. * responses are available. After you receive this notification, a
  896. * further call to the get_userpass_input function will return the
  897. * final state of the prompts system, which is guaranteed not to
  898. * be negative for 'still ongoing'.
  899. */
  900. toplevel_callback_fn_t callback;
  901. void *callback_ctx;
  902. /*
  903. * When this prompts_t is known to an Ldisc, we might need to
  904. * break the connection if things get freed in an emergency. So
  905. * this is a pointer to the Ldisc's pointer to us.
  906. */
  907. prompts_t **ldisc_ptr_to_us;
  908. };
  909. prompts_t *new_prompts(void);
  910. void add_prompt(prompts_t *p, char *promptstr, bool echo);
  911. void prompt_set_result(prompt_t *pr, const char *newstr);
  912. char *prompt_get_result(prompt_t *pr);
  913. const char *prompt_get_result_ref(prompt_t *pr);
  914. void free_prompts(prompts_t *p);
  915. /*
  916. * Data type definitions for true-colour terminal display.
  917. * 'optionalrgb' describes a single RGB colour, which overrides the
  918. * other colour settings if 'enabled' is nonzero, and is ignored
  919. * otherwise. 'truecolour' contains a pair of those for foreground and
  920. * background.
  921. */
  922. typedef struct optionalrgb {
  923. bool enabled;
  924. unsigned char r, g, b;
  925. } optionalrgb;
  926. extern const optionalrgb optionalrgb_none;
  927. typedef struct truecolour {
  928. optionalrgb fg, bg;
  929. } truecolour;
  930. #define optionalrgb_equal(r1,r2) ( \
  931. (r1).enabled==(r2).enabled && \
  932. (r1).r==(r2).r && (r1).g==(r2).g && (r1).b==(r2).b)
  933. #define truecolour_equal(c1,c2) ( \
  934. optionalrgb_equal((c1).fg, (c2).fg) && \
  935. optionalrgb_equal((c1).bg, (c2).bg))
  936. /*
  937. * Enumeration of clipboards. We provide some standard ones cross-
  938. * platform, and then permit each platform to extend this enumeration
  939. * further by defining PLATFORM_CLIPBOARDS in its own header file.
  940. *
  941. * CLIP_NULL is a non-clipboard, writes to which are ignored and reads
  942. * from which return no data.
  943. *
  944. * CLIP_LOCAL refers to a buffer within terminal.c, which
  945. * unconditionally saves the last data selected in the terminal. In
  946. * configurations where a system clipboard is not written
  947. * automatically on selection but instead by an explicit UI action,
  948. * this is where the code responding to that action can find the data
  949. * to write to the clipboard in question.
  950. */
  951. #define CROSS_PLATFORM_CLIPBOARDS(X) \
  952. X(CLIP_NULL, "null clipboard") \
  953. X(CLIP_LOCAL, "last text selected in terminal") \
  954. /* end of list */
  955. #define ALL_CLIPBOARDS(X) \
  956. CROSS_PLATFORM_CLIPBOARDS(X) \
  957. PLATFORM_CLIPBOARDS(X) \
  958. /* end of list */
  959. #define CLIP_ID(id,name) id,
  960. enum { ALL_CLIPBOARDS(CLIP_ID) N_CLIPBOARDS };
  961. #undef CLIP_ID
  962. /* Hint from backend to frontend about time-consuming operations, used
  963. * by seat_set_busy_status. Initial state is assumed to be
  964. * BUSY_NOT. */
  965. typedef enum BusyStatus {
  966. BUSY_NOT, /* Not busy, all user interaction OK */
  967. BUSY_WAITING, /* Waiting for something; local event loops still
  968. running so some local interaction (e.g. menus)
  969. OK, but network stuff is suspended */
  970. BUSY_CPU /* Locally busy (e.g. crypto); user interaction
  971. * suspended */
  972. } BusyStatus;
  973. typedef enum SeatInteractionContext {
  974. SIC_BANNER, SIC_KI_PROMPTS
  975. } SeatInteractionContext;
  976. typedef enum SeatOutputType {
  977. SEAT_OUTPUT_STDOUT, SEAT_OUTPUT_STDERR
  978. } SeatOutputType;
  979. typedef enum SeatDialogTextType {
  980. SDT_PARA, SDT_DISPLAY, SDT_SCARY_HEADING,
  981. SDT_TITLE, SDT_PROMPT, SDT_BATCH_ABORT,
  982. SDT_MORE_INFO_KEY, SDT_MORE_INFO_VALUE_SHORT, SDT_MORE_INFO_VALUE_BLOB
  983. } SeatDialogTextType;
  984. struct SeatDialogTextItem {
  985. SeatDialogTextType type;
  986. char *text;
  987. };
  988. struct SeatDialogText {
  989. size_t nitems, itemsize;
  990. SeatDialogTextItem *items;
  991. };
  992. SeatDialogText *seat_dialog_text_new(void);
  993. void seat_dialog_text_free(SeatDialogText *sdt);
  994. PRINTF_LIKE(3, 4) void seat_dialog_text_append(
  995. SeatDialogText *sdt, SeatDialogTextType type, const char *fmt, ...);
  996. /*
  997. * Data type 'Seat', which is an API intended to contain essentially
  998. * everything that a back end might need to talk to its client for:
  999. * session output, password prompts, SSH warnings about host keys and
  1000. * weak cryptography, notifications of events like the remote process
  1001. * exiting or the GUI specials menu needing an update.
  1002. */
  1003. struct Seat {
  1004. const struct SeatVtable *vt;
  1005. };
  1006. struct SeatVtable {
  1007. /*
  1008. * Provide output from the remote session. 'type' indicates the
  1009. * type of the output (stdout or stderr), which can be used to
  1010. * split the output into separate message channels, if the seat
  1011. * wants to handle them differently. But combining the channels
  1012. * into one is OK too; that's what terminal-window based seats do.
  1013. *
  1014. * The return value is the current size of the output backlog.
  1015. */
  1016. size_t (*output)(Seat *seat, SeatOutputType type,
  1017. const void *data, size_t len);
  1018. /*
  1019. * Called when the back end wants to indicate that EOF has arrived
  1020. * on the server-to-client stream. Returns false to indicate that
  1021. * we intend to keep the session open in the other direction, or
  1022. * true to indicate that if they're closing so are we.
  1023. */
  1024. bool (*eof)(Seat *seat);
  1025. /*
  1026. * Called by the back end to notify that the output backlog has
  1027. * changed size. A front end in control of the event loop won't
  1028. * necessarily need this (they can just keep checking it via
  1029. * backend_sendbuffer at every opportunity), but one buried in the
  1030. * depths of something else (like an SSH proxy) will need to be
  1031. * proactively notified that the amount of buffered data has
  1032. * become smaller.
  1033. */
  1034. void (*sent)(Seat *seat, size_t new_sendbuffer);
  1035. /*
  1036. * Provide authentication-banner output from the session setup.
  1037. * End-user Seats can treat this as very similar to 'output', but
  1038. * intermediate Seats in complex proxying situations will want to
  1039. * implement this and 'output' differently.
  1040. */
  1041. size_t (*banner)(Seat *seat, const void *data, size_t len);
  1042. /*
  1043. * Try to get answers from a set of interactive login prompts. The
  1044. * prompts are provided in 'p'.
  1045. *
  1046. * (FIXME: it would be nice to distinguish two classes of user-
  1047. * abort action, so the user could specify 'I want to abandon this
  1048. * entire attempt to start a session' or the milder 'I want to
  1049. * abandon this particular form of authentication and fall back to
  1050. * a different one' - e.g. if you turn out not to be able to
  1051. * remember your private key passphrase then perhaps you'd rather
  1052. * fall back to password auth rather than aborting the whole
  1053. * session.)
  1054. */
  1055. SeatPromptResult (*get_userpass_input)(Seat *seat, prompts_t *p);
  1056. /*
  1057. * Notify the seat that the main session channel has been
  1058. * successfully set up.
  1059. *
  1060. * This is only used as part of the SSH proxying system, so it's
  1061. * not necessary to implement it in all backends. A backend must
  1062. * call this if it advertises the BACKEND_NOTIFIES_SESSION_START
  1063. * flag, and otherwise, doesn't have to.
  1064. */
  1065. void (*notify_session_started)(Seat *seat);
  1066. /*
  1067. * Notify the seat that the process running at the other end of
  1068. * the connection has finished.
  1069. */
  1070. void (*notify_remote_exit)(Seat *seat);
  1071. /*
  1072. * Notify the seat that the whole connection has finished.
  1073. * (Distinct from notify_remote_exit, e.g. in the case where you
  1074. * have port forwardings still active when the main foreground
  1075. * session goes away: then you'd get notify_remote_exit when the
  1076. * foreground session dies, but notify_remote_disconnect when the
  1077. * last forwarding vanishes and the network connection actually
  1078. * closes.)
  1079. *
  1080. * This function might be called multiple times by accident; seats
  1081. * should be prepared to cope.
  1082. *
  1083. * More precisely: this function notifies the seat that
  1084. * backend_connected() might now return false where previously it
  1085. * returned true. (Note the 'might': an accidental duplicate call
  1086. * might happen when backend_connected() was already returning
  1087. * false. Or even, in weird situations, when it hadn't stopped
  1088. * returning true yet. The point is, when you get this
  1089. * notification, all it's really telling you is that it's worth
  1090. * _checking_ backend_connected, if you weren't already.)
  1091. */
  1092. void (*notify_remote_disconnect)(Seat *seat);
  1093. /*
  1094. * Notify the seat that the connection has suffered an error,
  1095. * either fatal to the whole connection or not.
  1096. *
  1097. * The latter kind of error is expected to be things along the
  1098. * lines of 'I/O error storing the new host key', which has
  1099. * traditionally been presented via a dialog box or similar.
  1100. */
  1101. void (*connection_fatal)(Seat *seat, const char *message);
  1102. void (*nonfatal)(Seat *seat, const char *message);
  1103. /*
  1104. * Notify the seat that the list of special commands available
  1105. * from backend_get_specials() has changed, so that it might want
  1106. * to call that function to repopulate its menu.
  1107. *
  1108. * Seats are not expected to call backend_get_specials()
  1109. * proactively; they may start by assuming that the backend
  1110. * provides no special commands at all, so if the backend does
  1111. * provide any, then it should use this notification at startup
  1112. * time. Of course it can also invoke it later if the set of
  1113. * special commands changes.
  1114. *
  1115. * It does not need to invoke it at session shutdown.
  1116. */
  1117. void (*update_specials_menu)(Seat *seat);
  1118. /*
  1119. * Get the seat's preferred value for an SSH terminal mode
  1120. * setting. Returning NULL indicates no preference (i.e. the SSH
  1121. * connection will not attempt to set the mode at all).
  1122. *
  1123. * The returned value is dynamically allocated, and the caller
  1124. * should free it.
  1125. */
  1126. char *(*get_ttymode)(Seat *seat, const char *mode);
  1127. /*
  1128. * Tell the seat whether the backend is currently doing anything
  1129. * CPU-intensive (typically a cryptographic key exchange). See
  1130. * BusyStatus enumeration above.
  1131. */
  1132. void (*set_busy_status)(Seat *seat, BusyStatus status);
  1133. /*
  1134. * Ask the seat whether a given SSH host key should be accepted.
  1135. * This is called after we've already checked it by any means we
  1136. * can do ourselves, such as checking against host key
  1137. * fingerprints in the Conf or the host key cache on disk: once we
  1138. * call this function, we've already decided there's nothing for
  1139. * it but to prompt the user.
  1140. *
  1141. * 'mismatch' reports the result of checking the host key cache:
  1142. * it is true if the server has presented a host key different
  1143. * from the one we expected, and false if we had no expectation in
  1144. * the first place.
  1145. *
  1146. * This call may prompt the user synchronously and not return
  1147. * until the answer is available, or it may present the prompt and
  1148. * return immediately, giving the answer later via the provided
  1149. * callback.
  1150. *
  1151. * Return values:
  1152. *
  1153. * - +1 means `user approved the key, so continue with the
  1154. * connection'
  1155. *
  1156. * - 0 means `user rejected the key, abandon the connection'
  1157. *
  1158. * - -1 means `I've initiated enquiries, please wait to be called
  1159. * back via the provided function with a result that's either 0
  1160. * or +1'.
  1161. */
  1162. SeatPromptResult (*confirm_ssh_host_key)(
  1163. Seat *seat, const char *host, int port, const char *keytype,
  1164. char *keystr, SeatDialogText *text, HelpCtx helpctx,
  1165. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1166. /*
  1167. * Check with the seat whether it's OK to use a cryptographic
  1168. * primitive from below the 'warn below this line' threshold in
  1169. * the input Conf. Return values are the same as
  1170. * confirm_ssh_host_key above.
  1171. */
  1172. SeatPromptResult (*confirm_weak_crypto_primitive)(
  1173. Seat *seat, SeatDialogText *text,
  1174. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1175. /*
  1176. * Variant form of confirm_weak_crypto_primitive, which prints a
  1177. * slightly different message but otherwise has the same
  1178. * semantics.
  1179. *
  1180. * This form is used in the case where we're using a host key
  1181. * below the warning threshold because that's the best one we have
  1182. * cached, but at least one host key algorithm *above* the
  1183. * threshold is available that we don't have cached.
  1184. */
  1185. SeatPromptResult (*confirm_weak_cached_hostkey)(
  1186. Seat *seat, SeatDialogText *text,
  1187. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1188. /*
  1189. * Some snippets of text describing the UI actions in host key
  1190. * prompts / dialog boxes, to be used in ssh/common.c when it
  1191. * assembles the full text of those prompts.
  1192. */
  1193. const SeatDialogPromptDescriptions *(*prompt_descriptions)(Seat *seat);
  1194. /*
  1195. * Indicates whether the seat is expecting to interact with the
  1196. * user in the UTF-8 character set. (Affects e.g. visual erase
  1197. * handling in local line editing.)
  1198. */
  1199. bool (*is_utf8)(Seat *seat);
  1200. /*
  1201. * Notify the seat that the back end, and/or the ldisc between
  1202. * them, have changed their idea of whether they currently want
  1203. * local echo and/or local line editing enabled.
  1204. */
  1205. void (*echoedit_update)(Seat *seat, bool echoing, bool editing);
  1206. /*
  1207. * Return the local X display string relevant to a seat, or NULL
  1208. * if there isn't one or if the concept is meaningless.
  1209. */
  1210. const char *(*get_x_display)(Seat *seat);
  1211. /*
  1212. * Return the X11 id of the X terminal window relevant to a seat,
  1213. * by returning true and filling in the output pointer. Return
  1214. * false if there isn't one or if the concept is meaningless.
  1215. */
  1216. bool (*get_windowid)(Seat *seat, long *id_out);
  1217. /*
  1218. * Return the size of the terminal window in pixels. If the
  1219. * concept is meaningless or the information is unavailable,
  1220. * return false; otherwise fill in the output pointers and return
  1221. * true.
  1222. */
  1223. bool (*get_window_pixel_size)(Seat *seat, int *width, int *height);
  1224. /*
  1225. * Return a StripCtrlChars appropriate for sanitising untrusted
  1226. * terminal data (e.g. SSH banners, prompts) being sent to the
  1227. * user of this seat. May return NULL if no sanitisation is
  1228. * needed.
  1229. */
  1230. StripCtrlChars *(*stripctrl_new)(
  1231. Seat *seat, BinarySink *bs_out, SeatInteractionContext sic);
  1232. /*
  1233. * Set the seat's current idea of where output is coming from.
  1234. * True means that output is being generated by our own code base
  1235. * (and hence, can be trusted if it's asking you for secrets such
  1236. * as your passphrase); false means output is coming from the
  1237. * server.
  1238. */
  1239. void (*set_trust_status)(Seat *seat, bool trusted);
  1240. /*
  1241. * Query whether this Seat can do anything user-visible in
  1242. * response to set_trust_status.
  1243. *
  1244. * Returns true if the seat has a way to indicate this
  1245. * distinction. Returns false if not, in which case the backend
  1246. * should use a fallback defence against spoofing of PuTTY's local
  1247. * prompts by malicious servers.
  1248. */
  1249. bool (*can_set_trust_status)(Seat *seat);
  1250. /*
  1251. * Query whether this Seat's interactive prompt responses and its
  1252. * session input come from the same place.
  1253. *
  1254. * If false, this is used to suppress the final 'Press Return to
  1255. * begin session' anti-spoofing prompt in Plink. For example,
  1256. * Plink itself sets this flag if its standard input is redirected
  1257. * (and therefore not coming from the same place as the console
  1258. * it's sending its prompts to).
  1259. */
  1260. bool (*has_mixed_input_stream)(Seat *seat);
  1261. /*
  1262. * Ask the seat whether it would like verbose messages.
  1263. */
  1264. bool (*verbose)(Seat *seat);
  1265. /*
  1266. * Ask the seat whether it's an interactive program.
  1267. */
  1268. bool (*interactive)(Seat *seat);
  1269. /*
  1270. * Return the seat's current idea of where the output cursor is.
  1271. *
  1272. * Returns true if the seat has a cursor. Returns false if not.
  1273. */
  1274. bool (*get_cursor_position)(Seat *seat, int *x, int *y);
  1275. };
  1276. static inline size_t seat_output(
  1277. Seat *seat, SeatOutputType type, const void *data, size_t len)
  1278. { return seat->vt->output(seat, type, data, len); }
  1279. static inline bool seat_eof(Seat *seat)
  1280. { return seat->vt->eof(seat); }
  1281. static inline void seat_sent(Seat *seat, size_t bufsize)
  1282. { seat->vt->sent(seat, bufsize); }
  1283. static inline size_t seat_banner(
  1284. InteractionReadySeat iseat, const void *data, size_t len)
  1285. { return iseat.seat->vt->banner(iseat.seat, data, len); }
  1286. static inline SeatPromptResult seat_get_userpass_input(
  1287. InteractionReadySeat iseat, prompts_t *p)
  1288. { return iseat.seat->vt->get_userpass_input(iseat.seat, p); }
  1289. static inline void seat_notify_session_started(Seat *seat)
  1290. { seat->vt->notify_session_started(seat); }
  1291. static inline void seat_notify_remote_exit(Seat *seat)
  1292. { seat->vt->notify_remote_exit(seat); }
  1293. static inline void seat_notify_remote_disconnect(Seat *seat)
  1294. { seat->vt->notify_remote_disconnect(seat); }
  1295. static inline void seat_update_specials_menu(Seat *seat)
  1296. { seat->vt->update_specials_menu(seat); }
  1297. static inline char *seat_get_ttymode(Seat *seat, const char *mode)
  1298. { return seat->vt->get_ttymode(seat, mode); }
  1299. static inline void seat_set_busy_status(Seat *seat, BusyStatus status)
  1300. { seat->vt->set_busy_status(seat, status); }
  1301. static inline SeatPromptResult seat_confirm_ssh_host_key(
  1302. InteractionReadySeat iseat, const char *h, int p, const char *ktyp,
  1303. char *kstr, SeatDialogText *text, HelpCtx helpctx,
  1304. void (*cb)(void *ctx, SeatPromptResult result), void *ctx)
  1305. { return iseat.seat->vt->confirm_ssh_host_key(
  1306. iseat.seat, h, p, ktyp, kstr, text, helpctx, cb, ctx); }
  1307. static inline SeatPromptResult seat_confirm_weak_crypto_primitive(
  1308. InteractionReadySeat iseat, SeatDialogText *text,
  1309. void (*cb)(void *ctx, SeatPromptResult result), void *ctx)
  1310. { return iseat.seat->vt->confirm_weak_crypto_primitive(
  1311. iseat.seat, text, cb, ctx); }
  1312. static inline SeatPromptResult seat_confirm_weak_cached_hostkey(
  1313. InteractionReadySeat iseat, SeatDialogText *text,
  1314. void (*cb)(void *ctx, SeatPromptResult result), void *ctx)
  1315. { return iseat.seat->vt->confirm_weak_cached_hostkey(
  1316. iseat.seat, text, cb, ctx); }
  1317. static inline const SeatDialogPromptDescriptions *seat_prompt_descriptions(
  1318. Seat *seat)
  1319. { return seat->vt->prompt_descriptions(seat); }
  1320. static inline bool seat_is_utf8(Seat *seat)
  1321. { return seat->vt->is_utf8(seat); }
  1322. static inline void seat_echoedit_update(Seat *seat, bool ec, bool ed)
  1323. { seat->vt->echoedit_update(seat, ec, ed); }
  1324. static inline const char *seat_get_x_display(Seat *seat)
  1325. { return seat->vt->get_x_display(seat); }
  1326. static inline bool seat_get_windowid(Seat *seat, long *id_out)
  1327. { return seat->vt->get_windowid(seat, id_out); }
  1328. static inline bool seat_get_window_pixel_size(Seat *seat, int *w, int *h)
  1329. { return seat->vt->get_window_pixel_size(seat, w, h); }
  1330. static inline StripCtrlChars *seat_stripctrl_new(
  1331. Seat *seat, BinarySink *bs, SeatInteractionContext sic)
  1332. { return seat->vt->stripctrl_new(seat, bs, sic); }
  1333. static inline void seat_set_trust_status(Seat *seat, bool trusted)
  1334. { seat->vt->set_trust_status(seat, trusted); }
  1335. static inline bool seat_can_set_trust_status(Seat *seat)
  1336. { return seat->vt->can_set_trust_status(seat); }
  1337. static inline bool seat_has_mixed_input_stream(Seat *seat)
  1338. { return seat->vt->has_mixed_input_stream(seat); }
  1339. static inline bool seat_verbose(Seat *seat)
  1340. { return seat->vt->verbose(seat); }
  1341. static inline bool seat_interactive(Seat *seat)
  1342. { return seat->vt->interactive(seat); }
  1343. static inline bool seat_get_cursor_position(Seat *seat, int *x, int *y)
  1344. { return seat->vt->get_cursor_position(seat, x, y); }
  1345. /* Unlike the seat's actual method, the public entry points
  1346. * seat_connection_fatal and seat_nonfatal are wrapper functions with
  1347. * a printf-like API, defined in utils. */
  1348. void seat_connection_fatal(Seat *seat, const char *fmt, ...) PRINTF_LIKE(2, 3);
  1349. void seat_nonfatal(Seat *seat, const char *fmt, ...) PRINTF_LIKE(2, 3);
  1350. /* Handy aliases for seat_output which set is_stderr to a fixed value. */
  1351. static inline size_t seat_stdout(Seat *seat, const void *data, size_t len)
  1352. { return seat_output(seat, SEAT_OUTPUT_STDOUT, data, len); }
  1353. static inline size_t seat_stdout_pl(Seat *seat, ptrlen data)
  1354. { return seat_output(seat, SEAT_OUTPUT_STDOUT, data.ptr, data.len); }
  1355. static inline size_t seat_stderr(Seat *seat, const void *data, size_t len)
  1356. { return seat_output(seat, SEAT_OUTPUT_STDERR, data, len); }
  1357. static inline size_t seat_stderr_pl(Seat *seat, ptrlen data)
  1358. { return seat_output(seat, SEAT_OUTPUT_STDERR, data.ptr, data.len); }
  1359. /* Alternative API for seat_banner taking a ptrlen */
  1360. static inline size_t seat_banner_pl(InteractionReadySeat iseat, ptrlen data)
  1361. { return iseat.seat->vt->banner(iseat.seat, data.ptr, data.len); }
  1362. struct SeatDialogPromptDescriptions {
  1363. const char *hk_accept_action;
  1364. const char *hk_connect_once_action;
  1365. const char *hk_cancel_action, *hk_cancel_action_Participle;
  1366. const char *weak_accept_action, *weak_cancel_action;
  1367. };
  1368. /* In the utils subdir: print a message to the Seat which can't be
  1369. * spoofed by server-supplied auth-time output such as SSH banners */
  1370. void seat_antispoof_msg(InteractionReadySeat iseat, const char *msg);
  1371. /*
  1372. * Stub methods for seat implementations that want to use the obvious
  1373. * null handling for a given method.
  1374. *
  1375. * These are generally obvious, except for is_utf8, where you might
  1376. * plausibly want to return either fixed answer 'no' or 'yes'.
  1377. */
  1378. size_t nullseat_output(
  1379. Seat *seat, SeatOutputType type, const void *data, size_t len);
  1380. bool nullseat_eof(Seat *seat);
  1381. void nullseat_sent(Seat *seat, size_t bufsize);
  1382. size_t nullseat_banner(Seat *seat, const void *data, size_t len);
  1383. size_t nullseat_banner_to_stderr(Seat *seat, const void *data, size_t len);
  1384. SeatPromptResult nullseat_get_userpass_input(Seat *seat, prompts_t *p);
  1385. void nullseat_notify_session_started(Seat *seat);
  1386. void nullseat_notify_remote_exit(Seat *seat);
  1387. void nullseat_notify_remote_disconnect(Seat *seat);
  1388. void nullseat_connection_fatal(Seat *seat, const char *message);
  1389. void nullseat_nonfatal(Seat *seat, const char *message);
  1390. void nullseat_update_specials_menu(Seat *seat);
  1391. char *nullseat_get_ttymode(Seat *seat, const char *mode);
  1392. void nullseat_set_busy_status(Seat *seat, BusyStatus status);
  1393. SeatPromptResult nullseat_confirm_ssh_host_key(
  1394. Seat *seat, const char *host, int port, const char *keytype,
  1395. char *keystr, SeatDialogText *text, HelpCtx helpctx,
  1396. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1397. SeatPromptResult nullseat_confirm_weak_crypto_primitive(
  1398. Seat *seat, SeatDialogText *text,
  1399. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1400. SeatPromptResult nullseat_confirm_weak_cached_hostkey(
  1401. Seat *seat, SeatDialogText *text,
  1402. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1403. const SeatDialogPromptDescriptions *nullseat_prompt_descriptions(Seat *seat);
  1404. bool nullseat_is_never_utf8(Seat *seat);
  1405. bool nullseat_is_always_utf8(Seat *seat);
  1406. void nullseat_echoedit_update(Seat *seat, bool echoing, bool editing);
  1407. const char *nullseat_get_x_display(Seat *seat);
  1408. bool nullseat_get_windowid(Seat *seat, long *id_out);
  1409. bool nullseat_get_window_pixel_size(Seat *seat, int *width, int *height);
  1410. StripCtrlChars *nullseat_stripctrl_new(
  1411. Seat *seat, BinarySink *bs_out, SeatInteractionContext sic);
  1412. void nullseat_set_trust_status(Seat *seat, bool trusted);
  1413. bool nullseat_can_set_trust_status_yes(Seat *seat);
  1414. bool nullseat_can_set_trust_status_no(Seat *seat);
  1415. bool nullseat_has_mixed_input_stream_yes(Seat *seat);
  1416. bool nullseat_has_mixed_input_stream_no(Seat *seat);
  1417. bool nullseat_verbose_no(Seat *seat);
  1418. bool nullseat_verbose_yes(Seat *seat);
  1419. bool nullseat_interactive_no(Seat *seat);
  1420. bool nullseat_interactive_yes(Seat *seat);
  1421. bool nullseat_get_cursor_position(Seat *seat, int *x, int *y);
  1422. /*
  1423. * Seat functions provided by the platform's console-application
  1424. * support module (console.c in each platform subdirectory).
  1425. */
  1426. void console_connection_fatal(Seat *seat, const char *message);
  1427. void console_nonfatal(Seat *seat, const char *message);
  1428. SeatPromptResult console_confirm_ssh_host_key(
  1429. Seat *seat, const char *host, int port, const char *keytype,
  1430. char *keystr, SeatDialogText *text, HelpCtx helpctx,
  1431. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1432. SeatPromptResult console_confirm_weak_crypto_primitive(
  1433. Seat *seat, SeatDialogText *text,
  1434. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1435. SeatPromptResult console_confirm_weak_cached_hostkey(
  1436. Seat *seat, SeatDialogText *text,
  1437. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1438. StripCtrlChars *console_stripctrl_new(
  1439. Seat *seat, BinarySink *bs_out, SeatInteractionContext sic);
  1440. void console_set_trust_status(Seat *seat, bool trusted);
  1441. bool console_can_set_trust_status(Seat *seat);
  1442. bool console_has_mixed_input_stream(Seat *seat);
  1443. const SeatDialogPromptDescriptions *console_prompt_descriptions(Seat *seat);
  1444. /*
  1445. * Other centralised seat functions.
  1446. */
  1447. SeatPromptResult filexfer_get_userpass_input(Seat *seat, prompts_t *p);
  1448. bool cmdline_seat_verbose(Seat *seat);
  1449. /*
  1450. * TempSeat: a seat implementation that can be given to a backend
  1451. * temporarily while network proxy setup is using the real seat.
  1452. * Buffers output and trust-status changes until the real seat is
  1453. * available again.
  1454. */
  1455. /* Called by the proxy code to make a TempSeat. */
  1456. Seat *tempseat_new(Seat *real);
  1457. /* Query functions to tell if a Seat _is_ temporary, and if so, to
  1458. * return the underlying real Seat. */
  1459. bool is_tempseat(Seat *seat);
  1460. Seat *tempseat_get_real(Seat *seat);
  1461. /* Called by interactor_return_seat once the proxy connection has
  1462. * finished setting up (or failed), to pass on any buffered stuff to
  1463. * the real seat. */
  1464. void tempseat_flush(Seat *ts);
  1465. /* Frees a TempSeat, without flushing anything it has buffered. (Call
  1466. * this after tempseat_flush, or alternatively, when you were going to
  1467. * abandon the whole connection anyway.) */
  1468. void tempseat_free(Seat *ts);
  1469. typedef struct rgb {
  1470. uint8_t r, g, b;
  1471. } rgb;
  1472. /*
  1473. * Data type 'TermWin', which is a vtable encapsulating all the
  1474. * functionality that Terminal expects from its containing terminal
  1475. * window.
  1476. */
  1477. struct TermWin {
  1478. const struct TermWinVtable *vt;
  1479. };
  1480. struct TermWinVtable {
  1481. /*
  1482. * All functions listed here between setup_draw_ctx and
  1483. * free_draw_ctx expect to be _called_ between them too, so that
  1484. * the TermWin has a drawing context currently available.
  1485. *
  1486. * (Yes, even char_width, because e.g. the Windows implementation
  1487. * of TermWin handles it by loading the currently configured font
  1488. * into the HDC and doing a GDI query.)
  1489. */
  1490. bool (*setup_draw_ctx)(TermWin *);
  1491. /* Draw text in the window, during a painting operation */
  1492. void (*draw_text)(TermWin *, int x, int y, wchar_t *text, int len,
  1493. unsigned long attrs, int line_attrs, truecolour tc);
  1494. /* Draw the visible cursor. Expects you to have called do_text
  1495. * first (because it might just draw an underline over a character
  1496. * presumed to exist already), but also expects you to pass in all
  1497. * the details of the character under the cursor (because it might
  1498. * redraw it in different colours). */
  1499. void (*draw_cursor)(TermWin *, int x, int y, wchar_t *text, int len,
  1500. unsigned long attrs, int line_attrs, truecolour tc);
  1501. /* Draw the sigil indicating that a line of text has come from
  1502. * PuTTY itself rather than the far end (defence against end-of-
  1503. * authentication spoofing) */
  1504. void (*draw_trust_sigil)(TermWin *, int x, int y);
  1505. int (*char_width)(TermWin *, int uc);
  1506. void (*free_draw_ctx)(TermWin *);
  1507. void (*set_cursor_pos)(TermWin *, int x, int y);
  1508. /* set_raw_mouse_mode instructs the front end to start sending mouse events
  1509. * in raw mode suitable for translating into mouse-tracking terminal data
  1510. * (e.g. include scroll-wheel events and don't bother to identify double-
  1511. * and triple-clicks). set_raw_mouse_mode_pointer instructs the front end
  1512. * to change the mouse pointer shape to *indicate* raw mouse mode. */
  1513. void (*set_raw_mouse_mode)(TermWin *, bool enable);
  1514. void (*set_raw_mouse_mode_pointer)(TermWin *, bool enable);
  1515. void (*set_scrollbar)(TermWin *, int total, int start, int page);
  1516. void (*bell)(TermWin *, int mode);
  1517. void (*clip_write)(TermWin *, int clipboard, wchar_t *text, int *attrs,
  1518. truecolour *colours, int len, bool must_deselect);
  1519. void (*clip_request_paste)(TermWin *, int clipboard);
  1520. void (*refresh)(TermWin *);
  1521. /* request_resize asks the front end if the terminal can please be
  1522. * resized to (w,h) in characters. The front end MAY call
  1523. * term_size() in response to tell the terminal its new size
  1524. * (which MAY be the requested size, or some other size if the
  1525. * requested one can't be achieved). The front end MAY also not
  1526. * call term_size() at all. But the front end MUST reply to this
  1527. * request by calling term_resize_request_completed(), after the
  1528. * responding resize event has taken place (if any).
  1529. *
  1530. * The calls to term_size and term_resize_request_completed may be
  1531. * synchronous callbacks from within the call to request_resize(). */
  1532. void (*request_resize)(TermWin *, int w, int h);
  1533. void (*set_title)(TermWin *, const char *title, int codepage);
  1534. void (*set_icon_title)(TermWin *, const char *icontitle, int codepage);
  1535. /* set_minimised and set_maximised are assumed to set two
  1536. * independent settings, rather than a single three-way
  1537. * {min,normal,max} switch. The idea is that when you un-minimise
  1538. * the window it remembers whether to go back to normal or
  1539. * maximised. */
  1540. void (*set_minimised)(TermWin *, bool minimised);
  1541. void (*set_maximised)(TermWin *, bool maximised);
  1542. void (*move)(TermWin *, int x, int y);
  1543. void (*set_zorder)(TermWin *, bool top);
  1544. /* Set the colour palette that the TermWin will use to display
  1545. * text. One call to this function sets 'ncolours' consecutive
  1546. * colours in the OSC 4 sequence, starting at 'start'. */
  1547. void (*palette_set)(TermWin *, unsigned start, unsigned ncolours,
  1548. const rgb *colours);
  1549. /* Query the front end for any OS-local overrides to the default
  1550. * colours stored in Conf. The front end should set any it cares
  1551. * about by calling term_palette_override.
  1552. *
  1553. * The Terminal object is passed in as a parameter, because this
  1554. * can be called as a callback from term_init(). So the TermWin
  1555. * itself won't yet have been told where to find its Terminal
  1556. * object, because that doesn't happen until term_init
  1557. * returns. */
  1558. void (*palette_get_overrides)(TermWin *, Terminal *);
  1559. /* Notify the front end that the terminal's buffer of unprocessed
  1560. * output has reduced. (Front ends will likely pass this straight
  1561. * on to backend_unthrottle.) */
  1562. void (*unthrottle)(TermWin *, size_t bufsize);
  1563. };
  1564. static inline bool win_setup_draw_ctx(TermWin *win)
  1565. { return win->vt->setup_draw_ctx(win); }
  1566. static inline void win_draw_text(
  1567. TermWin *win, int x, int y, wchar_t *text, int len,
  1568. unsigned long attrs, int line_attrs, truecolour tc)
  1569. { win->vt->draw_text(win, x, y, text, len, attrs, line_attrs, tc); }
  1570. static inline void win_draw_cursor(
  1571. TermWin *win, int x, int y, wchar_t *text, int len,
  1572. unsigned long attrs, int line_attrs, truecolour tc)
  1573. { win->vt->draw_cursor(win, x, y, text, len, attrs, line_attrs, tc); }
  1574. static inline void win_draw_trust_sigil(TermWin *win, int x, int y)
  1575. { win->vt->draw_trust_sigil(win, x, y); }
  1576. static inline int win_char_width(TermWin *win, int uc)
  1577. { return win->vt->char_width(win, uc); }
  1578. static inline void win_free_draw_ctx(TermWin *win)
  1579. { win->vt->free_draw_ctx(win); }
  1580. static inline void win_set_cursor_pos(TermWin *win, int x, int y)
  1581. { win->vt->set_cursor_pos(win, x, y); }
  1582. static inline void win_set_raw_mouse_mode(TermWin *win, bool enable)
  1583. { win->vt->set_raw_mouse_mode(win, enable); }
  1584. static inline void win_set_raw_mouse_mode_pointer(TermWin *win, bool enable)
  1585. { win->vt->set_raw_mouse_mode_pointer(win, enable); }
  1586. static inline void win_set_scrollbar(TermWin *win, int t, int s, int p)
  1587. { win->vt->set_scrollbar(win, t, s, p); }
  1588. static inline void win_bell(TermWin *win, int mode)
  1589. { win->vt->bell(win, mode); }
  1590. static inline void win_clip_write(
  1591. TermWin *win, int clipboard, wchar_t *text, int *attrs,
  1592. truecolour *colours, int len, bool deselect)
  1593. { win->vt->clip_write(win, clipboard, text, attrs, colours, len, deselect); }
  1594. static inline void win_clip_request_paste(TermWin *win, int clipboard)
  1595. { win->vt->clip_request_paste(win, clipboard); }
  1596. static inline void win_refresh(TermWin *win)
  1597. { win->vt->refresh(win); }
  1598. static inline void win_request_resize(TermWin *win, int w, int h)
  1599. { win->vt->request_resize(win, w, h); }
  1600. static inline void win_set_title(TermWin *win, const char *title, int codepage)
  1601. { win->vt->set_title(win, title, codepage); }
  1602. static inline void win_set_icon_title(TermWin *win, const char *icontitle,
  1603. int codepage)
  1604. { win->vt->set_icon_title(win, icontitle, codepage); }
  1605. static inline void win_set_minimised(TermWin *win, bool minimised)
  1606. { win->vt->set_minimised(win, minimised); }
  1607. static inline void win_set_maximised(TermWin *win, bool maximised)
  1608. { win->vt->set_maximised(win, maximised); }
  1609. static inline void win_move(TermWin *win, int x, int y)
  1610. { win->vt->move(win, x, y); }
  1611. static inline void win_set_zorder(TermWin *win, bool top)
  1612. { win->vt->set_zorder(win, top); }
  1613. static inline void win_palette_set(
  1614. TermWin *win, unsigned start, unsigned ncolours, const rgb *colours)
  1615. { win->vt->palette_set(win, start, ncolours, colours); }
  1616. static inline void win_palette_get_overrides(TermWin *win, Terminal *term)
  1617. { win->vt->palette_get_overrides(win, term); }
  1618. static inline void win_unthrottle(TermWin *win, size_t size)
  1619. { win->vt->unthrottle(win, size); }
  1620. /*
  1621. * Global functions not specific to a connection instance.
  1622. */
  1623. void nonfatal(const char *, ...) PRINTF_LIKE(1, 2);
  1624. NORETURN void modalfatalbox(const char *, ...) PRINTF_LIKE(1, 2);
  1625. NORETURN void cleanup_exit(int);
  1626. /*
  1627. * Exports from conf.c, and a big enum (via parametric macro) of
  1628. * configuration option keys.
  1629. */
  1630. /* The master list of option keywords lives in conf.h */
  1631. enum config_primary_key {
  1632. #define CONF_OPTION(keyword, ...) CONF_ ## keyword,
  1633. #include "conf.h"
  1634. #undef CONF_OPTION
  1635. N_CONFIG_OPTIONS
  1636. };
  1637. /* Types that appear in Conf keys and values. */
  1638. enum {
  1639. /*
  1640. * CONF_TYPE_NONE is included in this enum because sometimes you
  1641. * need a placeholder for 'no type found'. (In Rust you'd leave it
  1642. * out, and use Option<ConfType> for those situations.)
  1643. *
  1644. * In particular, it's used as the subkey type for options that
  1645. * don't have subkeys.
  1646. */
  1647. CONF_TYPE_NONE,
  1648. /* Booleans, accessed via conf_get_bool and conf_set_bool */
  1649. CONF_TYPE_BOOL,
  1650. /* Integers, accessed via conf_get_int and conf_set_int */
  1651. CONF_TYPE_INT,
  1652. /*
  1653. * NUL-terminated char strings, accessed via conf_get_str and
  1654. * conf_set_str.
  1655. *
  1656. * Where character encoding is relevant, these are generally
  1657. * expected to be in the host system's default character encoding.
  1658. *
  1659. * (Character encoding might not be relevant at all: for example,
  1660. * if the string is going to be used as a shell command on Unix,
  1661. * then the exec system call will want a char string anyway.)
  1662. */
  1663. CONF_TYPE_STR,
  1664. /* NUL-terminated char strings encoded in UTF-8, accessed via
  1665. * conf_get_utf8 and conf_set_utf8. */
  1666. CONF_TYPE_UTF8,
  1667. /*
  1668. * A type that can be _either_ a char string in system encoding
  1669. * (aka CONF_TYPE_STR), _or_ a char string in UTF-8 (aka
  1670. * CONF_TYPE_UTF8). You can set it to be one or the other via
  1671. * conf_set_str or conf_set_utf8. To read it, you must use
  1672. * conf_get_str_ambi(), which returns a char string and a boolean
  1673. * telling you whether it's UTF-8.
  1674. *
  1675. * These can't be used as _keys_ in Conf, only as values. (If you
  1676. * used them as keys, you'd have to answer the difficult question
  1677. * of whether a UTF-8 and a non-UTF-8 string should be considered
  1678. * equal.)
  1679. */
  1680. CONF_TYPE_STR_AMBI,
  1681. /* PuTTY's OS-specific 'Filename' data type, accessed via
  1682. * conf_get_filename and conf_set_filename */
  1683. CONF_TYPE_FILENAME,
  1684. /* PuTTY's GUI-specific 'FontSpec' data type, accessed via
  1685. * conf_get_fontspec and conf_set_fontspec */
  1686. CONF_TYPE_FONT,
  1687. };
  1688. struct ConfKeyInfo {
  1689. int subkey_type;
  1690. int value_type;
  1691. union {
  1692. bool bval;
  1693. int ival;
  1694. const char *sval;
  1695. } default_value;
  1696. bool save_custom : 1;
  1697. bool load_custom : 1;
  1698. bool not_saved : 1;
  1699. const char *save_keyword;
  1700. const ConfSaveEnumType *storage_enum;
  1701. };
  1702. struct ConfSaveEnumType {
  1703. const ConfSaveEnumValue *values;
  1704. size_t nvalues;
  1705. };
  1706. struct ConfSaveEnumValue {
  1707. int confval, storageval;
  1708. bool obsolete;
  1709. };
  1710. extern const ConfKeyInfo conf_key_info[];
  1711. bool conf_enum_map_to_storage(const ConfSaveEnumType *etype,
  1712. int confval, int *storageval_out);
  1713. bool conf_enum_map_from_storage(const ConfSaveEnumType *etype,
  1714. int storageval, int *confval_out);
  1715. /* Functions handling configuration structures. */
  1716. Conf *conf_new(void); /* create an empty configuration */
  1717. void conf_free(Conf *conf);
  1718. void conf_clear(Conf *conf); /* likely only useful for test programs */
  1719. Conf *conf_copy(Conf *oldconf);
  1720. void conf_copy_into(Conf *dest, Conf *src);
  1721. /* Mandatory accessor functions: enforce by assertion that keys exist. */
  1722. bool conf_get_bool(Conf *conf, int key);
  1723. int conf_get_int(Conf *conf, int key);
  1724. int conf_get_int_int(Conf *conf, int key, int subkey);
  1725. char *conf_get_str(Conf *conf, int key); /* result still owned by conf */
  1726. char *conf_get_utf8(Conf *conf, int key); /* result still owned by conf */
  1727. char *conf_get_str_ambi( /* result still owned by conf; 'utf8' may be NULL */
  1728. Conf *conf, int key, bool *utf8);
  1729. char *conf_get_str_str(Conf *conf, int key, const char *subkey);
  1730. Filename *conf_get_filename(Conf *conf, int key);
  1731. FontSpec *conf_get_fontspec(Conf *conf, int key); /* still owned by conf */
  1732. /* Optional accessor function: return NULL if key does not exist. */
  1733. char *conf_get_str_str_opt(Conf *conf, int key, const char *subkey);
  1734. /* Accessor function to step through a string-subkeyed list.
  1735. * Returns the next subkey after the provided one, or the first if NULL.
  1736. * Returns NULL if there are none left.
  1737. * Both the return value and *subkeyout are still owned by conf. */
  1738. char *conf_get_str_strs(Conf *conf, int key, char *subkeyin, char **subkeyout);
  1739. /* Return the nth string subkey in a list. Owned by conf. NULL if beyond end */
  1740. char *conf_get_str_nthstrkey(Conf *conf, int key, int n);
  1741. /* Functions to set entries in configuration. Always copy their inputs. */
  1742. void conf_set_bool(Conf *conf, int key, bool value);
  1743. void conf_set_int(Conf *conf, int key, int value);
  1744. void conf_set_int_int(Conf *conf, int key, int subkey, int value);
  1745. void conf_set_str(Conf *conf, int key, const char *value);
  1746. void conf_set_utf8(Conf *conf, int key, const char *value);
  1747. bool conf_try_set_str(Conf *conf, int key, const char *value);
  1748. bool conf_try_set_utf8(Conf *conf, int key, const char *value);
  1749. void conf_set_str_str(Conf *conf, int key,
  1750. const char *subkey, const char *val);
  1751. void conf_del_str_str(Conf *conf, int key, const char *subkey);
  1752. void conf_set_filename(Conf *conf, int key, const Filename *val);
  1753. void conf_set_fontspec(Conf *conf, int key, const FontSpec *val);
  1754. /* Serialisation functions for Duplicate Session */
  1755. void conf_serialise(BinarySink *bs, Conf *conf);
  1756. bool conf_deserialise(Conf *conf, BinarySource *src);/*returns true on success*/
  1757. /*
  1758. * Functions to copy, free, serialise and deserialise FontSpecs.
  1759. * Provided per-platform, to go with the platform's idea of a
  1760. * FontSpec's contents.
  1761. *
  1762. * The full fontspec_new is declared in the platform header, because
  1763. * each platform may need it to have a different prototype, due to
  1764. * constructing fonts in different ways. But fontspec_new_default()
  1765. * will at least produce _some_ kind of a FontSpec, for use in
  1766. * situations where one needs to exist (e.g. to put in a Conf) and be
  1767. * freeable but won't actually be used for anything important.
  1768. */
  1769. FontSpec *fontspec_new_default(void);
  1770. FontSpec *fontspec_copy(const FontSpec *f);
  1771. void fontspec_free(FontSpec *f);
  1772. void fontspec_serialise(BinarySink *bs, FontSpec *f);
  1773. FontSpec *fontspec_deserialise(BinarySource *src);
  1774. /*
  1775. * Exports from each platform's noise.c.
  1776. */
  1777. typedef enum NoiseSourceId {
  1778. NOISE_SOURCE_TIME,
  1779. NOISE_SOURCE_IOID,
  1780. NOISE_SOURCE_IOLEN,
  1781. NOISE_SOURCE_KEY,
  1782. NOISE_SOURCE_MOUSEBUTTON,
  1783. NOISE_SOURCE_MOUSEPOS,
  1784. NOISE_SOURCE_MEMINFO,
  1785. NOISE_SOURCE_STAT,
  1786. NOISE_SOURCE_RUSAGE,
  1787. NOISE_SOURCE_FGWINDOW,
  1788. NOISE_SOURCE_CAPTURE,
  1789. NOISE_SOURCE_CLIPBOARD,
  1790. NOISE_SOURCE_QUEUE,
  1791. NOISE_SOURCE_CURSORPOS,
  1792. NOISE_SOURCE_THREADTIME,
  1793. NOISE_SOURCE_PROCTIME,
  1794. NOISE_SOURCE_PERFCOUNT,
  1795. NOISE_MAX_SOURCES
  1796. } NoiseSourceId;
  1797. void noise_get_heavy(void (*func) (void *, int));
  1798. void noise_get_light(void (*func) (void *, int));
  1799. void noise_regular(void);
  1800. void noise_ultralight(NoiseSourceId id, unsigned long data);
  1801. /*
  1802. * Exports from sshrand.c.
  1803. */
  1804. void random_save_seed(void);
  1805. void random_destroy_seed(void);
  1806. /*
  1807. * Exports from settings.c.
  1808. *
  1809. * load_settings() and do_defaults() return false if the provided
  1810. * session name didn't actually exist. But they still fill in the
  1811. * provided Conf with _something_.
  1812. */
  1813. const struct BackendVtable *backend_vt_from_name(const char *name);
  1814. const struct BackendVtable *backend_vt_from_proto(int proto);
  1815. char *get_remote_username(Conf *conf); /* dynamically allocated */
  1816. char *save_settings(const char *section, Conf *conf);
  1817. void save_open_settings(settings_w *sesskey, Conf *conf);
  1818. bool load_settings(const char *section, Conf *conf);
  1819. void load_open_settings(settings_r *sesskey, Conf *conf);
  1820. void get_sesslist(struct sesslist *, bool allocate);
  1821. bool do_defaults(const char *, Conf *);
  1822. void registry_cleanup(void);
  1823. void settings_set_default_protocol(int);
  1824. void settings_set_default_port(int);
  1825. /*
  1826. * Functions used by settings.c to provide platform-specific
  1827. * default settings.
  1828. *
  1829. * (The integer one is expected to return `def' if it has no clear
  1830. * opinion of its own. This is because there's no integer value
  1831. * which I can reliably set aside to indicate `nil'. The string
  1832. * function is perfectly all right returning NULL, of course. The
  1833. * Filename and FontSpec functions are _not allowed_ to fail to
  1834. * return, since these defaults _must_ be per-platform.)
  1835. *
  1836. * The 'Filename *' returned by platform_default_filename, and the
  1837. * 'FontSpec *' returned by platform_default_fontspec, have ownership
  1838. * transferred to the caller, and must be freed.
  1839. */
  1840. char *platform_default_s(const char *name);
  1841. bool platform_default_b(const char *name, bool def);
  1842. int platform_default_i(const char *name, int def);
  1843. Filename *platform_default_filename(const char *name);
  1844. FontSpec *platform_default_fontspec(const char *name);
  1845. /*
  1846. * Exports from terminal.c.
  1847. */
  1848. Terminal *term_init(Conf *, struct unicode_data *, TermWin *);
  1849. void term_free(Terminal *);
  1850. void term_size(Terminal *, int, int, int);
  1851. void term_resize_request_completed(Terminal *);
  1852. void term_paint(Terminal *, int, int, int, int, bool);
  1853. void term_scroll(Terminal *, int, int);
  1854. void term_scroll_to_selection(Terminal *, int);
  1855. void term_pwron(Terminal *, bool);
  1856. void term_clrsb(Terminal *);
  1857. void term_mouse(Terminal *, Mouse_Button, Mouse_Button, Mouse_Action,
  1858. int, int, bool, bool, bool);
  1859. void term_cancel_selection_drag(Terminal *);
  1860. void term_key(Terminal *, Key_Sym, wchar_t *, size_t, unsigned int,
  1861. unsigned int);
  1862. void term_lost_clipboard_ownership(Terminal *, int clipboard);
  1863. void term_update(Terminal *);
  1864. void term_invalidate(Terminal *);
  1865. void term_blink(Terminal *, bool set_cursor);
  1866. void term_do_paste(Terminal *, const wchar_t *, size_t);
  1867. void term_nopaste(Terminal *);
  1868. void term_copyall(Terminal *, const int *, int);
  1869. void term_pre_reconfig(Terminal *, Conf *);
  1870. void term_reconfig(Terminal *, Conf *);
  1871. void term_request_copy(Terminal *, const int *clipboards, int n_clipboards);
  1872. void term_request_paste(Terminal *, int clipboard);
  1873. void term_seen_key_event(Terminal *);
  1874. size_t term_data(Terminal *, const void *data, size_t len);
  1875. void term_provide_backend(Terminal *term, Backend *backend);
  1876. void term_provide_logctx(Terminal *term, LogContext *logctx);
  1877. void term_set_focus(Terminal *term, bool has_focus);
  1878. char *term_get_ttymode(Terminal *term, const char *mode);
  1879. SeatPromptResult term_get_userpass_input(Terminal *term, prompts_t *p);
  1880. void term_set_trust_status(Terminal *term, bool trusted);
  1881. void term_keyinput(Terminal *, int codepage, const void *buf, int len);
  1882. void term_keyinputw(Terminal *, const wchar_t *widebuf, int len);
  1883. void term_get_cursor_position(Terminal *term, int *x, int *y);
  1884. void term_setup_window_titles(Terminal *term, const char *title_hostname);
  1885. void term_notify_minimised(Terminal *term, bool minimised);
  1886. void term_notify_palette_changed(Terminal *term);
  1887. void term_notify_window_pos(Terminal *term, int x, int y);
  1888. void term_notify_window_size_pixels(Terminal *term, int x, int y);
  1889. void term_palette_override(Terminal *term, unsigned osc4_index, rgb rgb);
  1890. typedef enum SmallKeypadKey {
  1891. SKK_HOME, SKK_END, SKK_INSERT, SKK_DELETE, SKK_PGUP, SKK_PGDN,
  1892. } SmallKeypadKey;
  1893. int format_arrow_key(char *buf, Terminal *term, int xkey,
  1894. bool shift, bool ctrl, bool alt, bool *consumed_alt);
  1895. int format_function_key(char *buf, Terminal *term, int key_number,
  1896. bool shift, bool ctrl, bool alt, bool *consumed_alt);
  1897. int format_small_keypad_key(char *buf, Terminal *term, SmallKeypadKey key,
  1898. bool shift, bool ctrl, bool alt,
  1899. bool *consumed_alt);
  1900. int format_numeric_keypad_key(char *buf, Terminal *term, char key,
  1901. bool shift, bool ctrl);
  1902. /*
  1903. * Exports from logging.c.
  1904. */
  1905. struct LogPolicyVtable {
  1906. /*
  1907. * Pass Event Log entries on from LogContext to the front end,
  1908. * which might write them to standard error or save them for a GUI
  1909. * list box or other things.
  1910. */
  1911. void (*eventlog)(LogPolicy *lp, const char *event);
  1912. /*
  1913. * Ask what to do about the specified output log file already
  1914. * existing. Can return four values:
  1915. *
  1916. * - 2 means overwrite the log file
  1917. * - 1 means append to the log file
  1918. * - 0 means cancel logging for this session
  1919. * - -1 means please wait, and callback() will be called with one
  1920. * of those options.
  1921. */
  1922. int (*askappend)(LogPolicy *lp, Filename *filename,
  1923. void (*callback)(void *ctx, int result), void *ctx);
  1924. /*
  1925. * Emergency logging when the log file itself can't be opened,
  1926. * which typically means we want to shout about it more loudly
  1927. * than a mere Event Log entry.
  1928. *
  1929. * One reasonable option is to send it to the same place that
  1930. * stderr output from the main session goes (so, either a console
  1931. * tool's actual stderr, or a terminal window). In many cases this
  1932. * is unlikely to cause this error message to turn up
  1933. * embarrassingly in a log file of real server output, because the
  1934. * whole point is that we haven't managed to open any such log
  1935. * file :-)
  1936. */
  1937. void (*logging_error)(LogPolicy *lp, const char *event);
  1938. /*
  1939. * Ask whether extra verbose log messages are required.
  1940. */
  1941. bool (*verbose)(LogPolicy *lp);
  1942. };
  1943. struct LogPolicy {
  1944. const LogPolicyVtable *vt;
  1945. };
  1946. static inline void lp_eventlog(LogPolicy *lp, const char *event)
  1947. { lp->vt->eventlog(lp, event); }
  1948. static inline int lp_askappend(
  1949. LogPolicy *lp, Filename *filename,
  1950. void (*callback)(void *ctx, int result), void *ctx)
  1951. { return lp->vt->askappend(lp, filename, callback, ctx); }
  1952. static inline void lp_logging_error(LogPolicy *lp, const char *event)
  1953. { lp->vt->logging_error(lp, event); }
  1954. static inline bool lp_verbose(LogPolicy *lp)
  1955. { return lp->vt->verbose(lp); }
  1956. /* Defined in clicons.c, used in several console command-line tools */
  1957. extern LogPolicy console_cli_logpolicy[];
  1958. int console_askappend(LogPolicy *lp, Filename *filename,
  1959. void (*callback)(void *ctx, int result), void *ctx);
  1960. void console_logging_error(LogPolicy *lp, const char *string);
  1961. void console_eventlog(LogPolicy *lp, const char *string);
  1962. bool null_lp_verbose_yes(LogPolicy *lp);
  1963. bool null_lp_verbose_no(LogPolicy *lp);
  1964. bool cmdline_lp_verbose(LogPolicy *lp);
  1965. LogContext *log_init(LogPolicy *lp, Conf *conf);
  1966. void log_free(LogContext *logctx);
  1967. void log_reconfig(LogContext *logctx, Conf *conf);
  1968. void logfopen(LogContext *logctx);
  1969. void logfclose(LogContext *logctx);
  1970. void logtraffic(LogContext *logctx, unsigned char c, int logmode);
  1971. void logflush(LogContext *logctx);
  1972. LogPolicy *log_get_policy(LogContext *logctx);
  1973. void logevent(LogContext *logctx, const char *event);
  1974. void logeventf(LogContext *logctx, const char *fmt, ...) PRINTF_LIKE(2, 3);
  1975. void logeventvf(LogContext *logctx, const char *fmt, va_list ap);
  1976. /*
  1977. * Pass a dynamically allocated string to logevent and immediately
  1978. * free it. Intended for use by wrapper macros which pass the return
  1979. * value of dupprintf straight to this.
  1980. */
  1981. void logevent_and_free(LogContext *logctx, char *event);
  1982. enum { PKT_INCOMING, PKT_OUTGOING };
  1983. enum { PKTLOG_EMIT, PKTLOG_BLANK, PKTLOG_OMIT };
  1984. struct logblank_t {
  1985. int offset;
  1986. int len;
  1987. int type;
  1988. };
  1989. void log_packet(LogContext *logctx, int direction, int type,
  1990. const char *texttype, const void *data, size_t len,
  1991. int n_blanks, const struct logblank_t *blanks,
  1992. const unsigned long *sequence,
  1993. unsigned downstream_id, const char *additional_log_text);
  1994. /*
  1995. * Exports from testback.c
  1996. */
  1997. extern const struct BackendVtable null_backend;
  1998. extern const struct BackendVtable loop_backend;
  1999. /*
  2000. * Exports from raw.c.
  2001. */
  2002. extern const struct BackendVtable raw_backend;
  2003. /*
  2004. * Exports from rlogin.c.
  2005. */
  2006. extern const struct BackendVtable rlogin_backend;
  2007. /*
  2008. * Exports from telnet.c.
  2009. */
  2010. extern const struct BackendVtable telnet_backend;
  2011. /*
  2012. * Exports from ssh/ssh.c.
  2013. */
  2014. extern const struct BackendVtable ssh_backend;
  2015. extern const struct BackendVtable sshconn_backend;
  2016. /*
  2017. * Exports from supdup.c.
  2018. */
  2019. extern const struct BackendVtable supdup_backend;
  2020. /*
  2021. * Exports from ldisc.c.
  2022. */
  2023. Ldisc *ldisc_create(Conf *, Terminal *, Backend *, Seat *);
  2024. void ldisc_configure(Ldisc *, Conf *);
  2025. void ldisc_free(Ldisc *);
  2026. void ldisc_send(Ldisc *, const void *buf, int len, bool interactive);
  2027. void ldisc_echoedit_update(Ldisc *);
  2028. void ldisc_provide_userpass_le(Ldisc *, TermLineEditor *);
  2029. void ldisc_check_sendok(Ldisc *);
  2030. /*
  2031. * Exports from sshrand.c.
  2032. */
  2033. void random_add_noise(NoiseSourceId source, const void *noise, int length);
  2034. void random_read(void *buf, size_t size);
  2035. void random_get_savedata(void **data, int *len);
  2036. extern int random_active;
  2037. /* The random number subsystem is activated if at least one other entity
  2038. * within the program expresses an interest in it. So each SSH session
  2039. * calls random_ref on startup and random_unref on shutdown. */
  2040. void random_ref(void);
  2041. void random_unref(void);
  2042. /* random_clear is equivalent to calling random_unref as many times as
  2043. * necessary to shut down the global PRNG instance completely. It's
  2044. * not needed in normal applications, but the command-line PuTTYgen
  2045. * test finds it useful to clean up after each invocation of the
  2046. * logical main() no matter whether it needed random numbers or
  2047. * not. */
  2048. void random_clear(void);
  2049. /* random_setup_custom sets up the process-global random number
  2050. * generator specially, with a hash function of your choice. */
  2051. void random_setup_custom(const ssh_hashalg *hash);
  2052. /* random_setup_special() is a macro wrapper on that, which makes an
  2053. * extra-big one based on the largest hash function we have. It's
  2054. * defined this way to avoid what would otherwise be an unnecessary
  2055. * module dependency from sshrand.c to a hash function implementation. */
  2056. #define random_setup_special() random_setup_custom(&ssh_shake256_114bytes)
  2057. /* Manually drop a random seed into the random number generator, e.g.
  2058. * just before generating a key. */
  2059. void random_reseed(ptrlen seed);
  2060. /* Limit on how much entropy is worth putting into the generator (bits). */
  2061. size_t random_seed_bits(void);
  2062. /*
  2063. * Exports from pinger.c.
  2064. */
  2065. typedef struct Pinger Pinger;
  2066. Pinger *pinger_new(Conf *conf, Backend *backend);
  2067. void pinger_reconfig(Pinger *, Conf *oldconf, Conf *newconf);
  2068. void pinger_free(Pinger *);
  2069. /*
  2070. * Exports from modules in utils.
  2071. */
  2072. #include "misc.h"
  2073. bool conf_launchable(Conf *conf);
  2074. char const *conf_dest(Conf *conf);
  2075. /*
  2076. * Exports from sessprep.c.
  2077. */
  2078. void prepare_session(Conf *conf);
  2079. /*
  2080. * Exports from version.c and cmake_commit.c.
  2081. */
  2082. extern const char ver[];
  2083. extern const char commitid[];
  2084. /*
  2085. * Exports from unicode.c in platform subdirs.
  2086. */
  2087. /* void init_ucs(void); -- this is now in platform-specific headers */
  2088. bool is_dbcs_leadbyte(int codepage, char byte);
  2089. /* For put_mb_to_wc / put_wc_to_mb, see marshal.h */
  2090. wchar_t xlat_uskbd2cyrllic(int ch);
  2091. int check_compose(int first, int second);
  2092. int decode_codepage(const char *cp_name);
  2093. const char *cp_enumerate (int index);
  2094. const char *cp_name(int codepage);
  2095. void get_unitab(int codepage, wchar_t *unitab, int ftype);
  2096. /*
  2097. * Exports from wcwidth.c
  2098. */
  2099. int mk_wcwidth(unsigned int ucs);
  2100. int mk_wcswidth(const unsigned int *pwcs, size_t n);
  2101. int mk_wcwidth_cjk(unsigned int ucs);
  2102. int mk_wcswidth_cjk(const unsigned int *pwcs, size_t n);
  2103. /*
  2104. * Exports from agent-client.c in platform subdirs.
  2105. *
  2106. * agent_query returns NULL for here's-a-response, and non-NULL for
  2107. * query-in- progress. In the latter case there will be a call to
  2108. * `callback' at some future point, passing callback_ctx as the first
  2109. * parameter and the actual reply data as the second and third.
  2110. *
  2111. * The response may be a NULL pointer (in either of the synchronous
  2112. * or asynchronous cases), which indicates failure to receive a
  2113. * response.
  2114. *
  2115. * When the return from agent_query is not NULL, it identifies the
  2116. * in-progress query in case it needs to be cancelled. If
  2117. * agent_cancel_query is called, then the pending query is destroyed
  2118. * and the callback will not be called. (E.g. if you're going to throw
  2119. * away the thing you were using as callback_ctx.)
  2120. *
  2121. * Passing a null pointer as callback forces agent_query to behave
  2122. * synchronously, i.e. it will block if necessary, and guarantee to
  2123. * return NULL. The wrapper function agent_query_synchronous()
  2124. * (defined in its own module aqsync.c) makes this easier.
  2125. */
  2126. typedef struct agent_pending_query agent_pending_query;
  2127. agent_pending_query *agent_query(
  2128. strbuf *in, void **out, int *outlen,
  2129. void (*callback)(void *, void *, int), void *callback_ctx);
  2130. void agent_cancel_query(agent_pending_query *);
  2131. void agent_query_synchronous(strbuf *in, void **out, int *outlen);
  2132. bool agent_exists(void);
  2133. /* For stream-oriented agent connections, if available. */
  2134. Socket *agent_connect(Plug *plug);
  2135. /*
  2136. * Exports from wildcard.c
  2137. */
  2138. const char *wc_error(int value);
  2139. int wc_match_pl(const char *wildcard, ptrlen target);
  2140. int wc_match(const char *wildcard, const char *target);
  2141. bool wc_unescape(char *output, const char *wildcard);
  2142. /*
  2143. * Exports from frontend (dialog.c etc)
  2144. */
  2145. void pgp_fingerprints(void);
  2146. /*
  2147. * have_ssh_host_key() just returns true if a key of that type is
  2148. * already cached and false otherwise.
  2149. */
  2150. bool have_ssh_host_key(const char *host, int port, const char *keytype);
  2151. /*
  2152. * Exports from console frontends (console.c in platform subdirs)
  2153. * that aren't equivalents to things in windlg.c et al.
  2154. */
  2155. extern bool console_batch_mode, console_antispoof_prompt;
  2156. extern bool console_set_batch_mode(bool);
  2157. extern bool console_set_stdio_prompts(bool);
  2158. SeatPromptResult console_get_userpass_input(prompts_t *p);
  2159. bool is_interactive(void);
  2160. void console_print_error_msg(const char *prefix, const char *msg);
  2161. void console_print_error_msg_fmt_v(
  2162. const char *prefix, const char *fmt, va_list ap);
  2163. void console_print_error_msg_fmt(const char *prefix, const char *fmt, ...)
  2164. PRINTF_LIKE(2, 3);
  2165. /*
  2166. * Exports from either console frontends or terminal.c.
  2167. */
  2168. extern bool set_legacy_charset_handling(bool);
  2169. /*
  2170. * Exports from printing.c in platform subdirs.
  2171. */
  2172. typedef struct printer_enum_tag printer_enum;
  2173. typedef struct printer_job_tag printer_job;
  2174. printer_enum *printer_start_enum(int *nprinters);
  2175. char *printer_get_name(printer_enum *, int);
  2176. void printer_finish_enum(printer_enum *);
  2177. printer_job *printer_start_job(char *printer);
  2178. void printer_job_data(printer_job *, const void *, size_t);
  2179. void printer_finish_job(printer_job *);
  2180. /*
  2181. * Exports from cmdline.c (and also cmdline_error(), which is
  2182. * defined differently in various places and required _by_
  2183. * cmdline.c).
  2184. */
  2185. struct cmdline_get_passwd_input_state { bool tried; };
  2186. #define CMDLINE_GET_PASSWD_INPUT_STATE_INIT { .tried = false }
  2187. extern const cmdline_get_passwd_input_state cmdline_get_passwd_input_state_new;
  2188. int cmdline_process_param(CmdlineArg *, CmdlineArg *, int, Conf *);
  2189. void cmdline_run_saved(Conf *);
  2190. void cmdline_cleanup(void);
  2191. SeatPromptResult cmdline_get_passwd_input(
  2192. prompts_t *p, cmdline_get_passwd_input_state *state, bool restartable);
  2193. bool cmdline_host_ok(Conf *);
  2194. bool cmdline_verbose(void);
  2195. bool cmdline_loaded_session(void);
  2196. /*
  2197. * Abstraction provided by each platform to represent a command-line
  2198. * argument. May not be as simple as a default-encoded string: on
  2199. * Windows, command lines can be Unicode representing characters not
  2200. * in the system codepage, so you might need to retrieve the argument
  2201. * in a richer form.
  2202. */
  2203. struct CmdlineArgList {
  2204. /* args[0], args[1], ... represent the original arguments in the
  2205. * command line. Then there's a null pointer. Further arguments
  2206. * can be invented to add to the array after that, in which case
  2207. * they'll be freed with the rest of the CmdlineArgList, but
  2208. * aren't logically part of the original command line. */
  2209. CmdlineArg **args;
  2210. size_t nargs, argssize;
  2211. };
  2212. struct CmdlineArg {
  2213. CmdlineArgList *list;
  2214. };
  2215. const char *cmdline_arg_to_utf8(CmdlineArg *arg); /* may fail */
  2216. const char *cmdline_arg_to_str(CmdlineArg *arg); /* must not fail */
  2217. Filename *cmdline_arg_to_filename(CmdlineArg *arg); /* caller must free */
  2218. void cmdline_arg_wipe(CmdlineArg *arg);
  2219. CmdlineArg *cmdline_arg_from_str(CmdlineArgList *list, const char *string);
  2220. /* Platforms provide their own constructors for CmdlineArgList */
  2221. void cmdline_arg_list_free(CmdlineArgList *list);
  2222. /*
  2223. * Here we have a flags word provided by each tool, which describes
  2224. * the capabilities of that tool that cmdline.c needs to know about.
  2225. * It will refuse certain command-line options if a particular tool
  2226. * inherently can't do anything sensible. For example, the file
  2227. * transfer tools (psftp, pscp) can't do a great deal with protocol
  2228. * selections (ever tried running scp over telnet?) or with port
  2229. * forwarding (even if it wasn't a hideously bad idea, they don't have
  2230. * the select/poll infrastructure to make them work).
  2231. */
  2232. extern const unsigned cmdline_tooltype;
  2233. /* Bit flags for the above */
  2234. #define TOOLTYPE_LIST(X) \
  2235. X(TOOLTYPE_FILETRANSFER) \
  2236. X(TOOLTYPE_NONNETWORK) \
  2237. X(TOOLTYPE_HOST_ARG) \
  2238. X(TOOLTYPE_HOST_ARG_CAN_BE_SESSION) \
  2239. X(TOOLTYPE_HOST_ARG_PROTOCOL_PREFIX) \
  2240. X(TOOLTYPE_HOST_ARG_FROM_LAUNCHABLE_LOAD) \
  2241. X(TOOLTYPE_PORT_ARG) \
  2242. X(TOOLTYPE_NO_VERBOSE_OPTION) \
  2243. X(TOOLTYPE_GUI) \
  2244. /* end of list */
  2245. #define BITFLAG_INDEX(val) val ## _bitflag_index,
  2246. enum { TOOLTYPE_LIST(BITFLAG_INDEX) };
  2247. #define BITFLAG_DEF(val) val = 1U << (val ## _bitflag_index),
  2248. enum { TOOLTYPE_LIST(BITFLAG_DEF) };
  2249. void cmdline_error(const char *, ...) PRINTF_LIKE(1, 2);
  2250. /*
  2251. * Exports from config.c.
  2252. */
  2253. struct controlbox;
  2254. void conf_radiobutton_handler(dlgcontrol *ctrl, dlgparam *dlg,
  2255. void *data, int event);
  2256. #define CHECKBOX_INVERT (1<<30)
  2257. void conf_checkbox_handler(dlgcontrol *ctrl, dlgparam *dlg,
  2258. void *data, int event);
  2259. void conf_editbox_handler(dlgcontrol *ctrl, dlgparam *dlg,
  2260. void *data, int event);
  2261. void conf_filesel_handler(dlgcontrol *ctrl, dlgparam *dlg,
  2262. void *data, int event);
  2263. void conf_fontsel_handler(dlgcontrol *ctrl, dlgparam *dlg,
  2264. void *data, int event);
  2265. struct conf_editbox_handler_type {
  2266. /* Structure passed as context2 to conf_editbox_handler */
  2267. enum { EDIT_STR, EDIT_INT, EDIT_FIXEDPOINT } type;
  2268. union {
  2269. /*
  2270. * EDIT_STR means the edit box is connected to a string
  2271. * field in Conf. No further parameters needed.
  2272. */
  2273. /*
  2274. * EDIT_INT means the edit box is connected to an int field in
  2275. * Conf, and the input string is interpreted as decimal. No
  2276. * further parameters needed. (But we could add one here later
  2277. * if for some reason we wanted int fields in hex.)
  2278. */
  2279. /*
  2280. * EDIT_FIXEDPOINT means the edit box is connected to an int
  2281. * field in Conf, but the input string is interpreted as
  2282. * _floating point_, and converted to/from the output int by
  2283. * means of a fixed denominator. That is,
  2284. *
  2285. * (floating value in edit box) * denominator = value in Conf
  2286. */
  2287. struct {
  2288. double denominator;
  2289. };
  2290. };
  2291. };
  2292. extern const struct conf_editbox_handler_type conf_editbox_str;
  2293. extern const struct conf_editbox_handler_type conf_editbox_int;
  2294. #define ED_STR CP(&conf_editbox_str)
  2295. #define ED_INT CP(&conf_editbox_int)
  2296. void setup_config_box(struct controlbox *b, bool midsession,
  2297. int protocol, int protcfginfo);
  2298. void setup_ca_config_box(struct controlbox *b);
  2299. /* Platforms provide this to be called from config.c */
  2300. void show_ca_config_box(dlgparam *dlg);
  2301. extern const bool has_ca_config_box; /* false if, e.g., we're PuTTYtel */
  2302. /* Visible outside config.c so that platforms can use it to recognise
  2303. * the proxy type control */
  2304. void proxy_type_handler(dlgcontrol *ctrl, dlgparam *dlg,
  2305. void *data, int event);
  2306. /* And then they'll set this flag in its generic.context.i */
  2307. #define PROXY_UI_FLAG_LOCAL 1 /* has a local proxy */
  2308. /*
  2309. * Exports from bidi.c.
  2310. */
  2311. #define BIDI_CHAR_INDEX_NONE ((unsigned short)-1)
  2312. typedef struct bidi_char {
  2313. unsigned int origwc, wc;
  2314. unsigned short index, nchars;
  2315. } bidi_char;
  2316. BidiContext *bidi_new_context(void);
  2317. void bidi_free_context(BidiContext *ctx);
  2318. void do_bidi(BidiContext *ctx, bidi_char *line, size_t count);
  2319. int do_shape(bidi_char *line, bidi_char *to, int count);
  2320. bool is_rtl(int c);
  2321. /*
  2322. * X11 auth mechanisms we know about.
  2323. */
  2324. enum {
  2325. X11_NO_AUTH,
  2326. X11_MIT, /* MIT-MAGIC-COOKIE-1 */
  2327. X11_XDM, /* XDM-AUTHORIZATION-1 */
  2328. X11_NAUTHS
  2329. };
  2330. extern const char *const x11_authnames[X11_NAUTHS];
  2331. /*
  2332. * An enum for the copy-paste UI action configuration.
  2333. */
  2334. enum {
  2335. CLIPUI_NONE, /* UI action has no copy/paste effect */
  2336. CLIPUI_IMPLICIT, /* use the default clipboard implicit in mouse actions */
  2337. CLIPUI_EXPLICIT, /* use the default clipboard for explicit Copy/Paste */
  2338. CLIPUI_CUSTOM, /* use a named clipboard (on systems that support it) */
  2339. };
  2340. /*
  2341. * Miscellaneous exports from the platform-specific code.
  2342. *
  2343. * filename_serialise and filename_deserialise have the same semantics
  2344. * as fontspec_serialise and fontspec_deserialise above.
  2345. */
  2346. Filename *filename_from_str(const char *string);
  2347. const char *filename_to_str(const Filename *fn);
  2348. bool filename_equal(const Filename *f1, const Filename *f2);
  2349. bool filename_is_null(const Filename *fn);
  2350. Filename *filename_copy(const Filename *fn);
  2351. void filename_free(Filename *fn);
  2352. void filename_serialise(BinarySink *bs, const Filename *f);
  2353. Filename *filename_deserialise(BinarySource *src);
  2354. char *get_username(void); /* return value needs freeing */
  2355. char *get_random_data(int bytes, const char *device); /* used in cmdgen.c */
  2356. char filename_char_sanitise(char c); /* rewrite special pathname chars */
  2357. bool open_for_write_would_lose_data(const Filename *fn);
  2358. /*
  2359. * Exports and imports from timing.c.
  2360. *
  2361. * schedule_timer() asks the front end to schedule a callback to a
  2362. * timer function in a given number of ticks. The returned value is
  2363. * the time (in ticks since an arbitrary offset) at which the
  2364. * callback can be expected. This value will also be passed as the
  2365. * `now' parameter to the callback function. Hence, you can (for
  2366. * example) schedule an event at a particular time by calling
  2367. * schedule_timer() and storing the return value in your context
  2368. * structure as the time when that event is due. The first time a
  2369. * callback function gives you that value or more as `now', you do
  2370. * the thing.
  2371. *
  2372. * expire_timer_context() drops all current timers associated with
  2373. * a given value of ctx (for when you're about to free ctx).
  2374. *
  2375. * run_timers() is called from the front end when it has reason to
  2376. * think some timers have reached their moment, or when it simply
  2377. * needs to know how long to wait next. We pass it the time we
  2378. * think it is. It returns true and places the time when the next
  2379. * timer needs to go off in `next', or alternatively it returns
  2380. * false if there are no timers at all pending.
  2381. *
  2382. * timer_change_notify() must be supplied by the front end; it
  2383. * notifies the front end that a new timer has been added to the
  2384. * list which is sooner than any existing ones. It provides the
  2385. * time when that timer needs to go off.
  2386. *
  2387. * *** FRONT END IMPLEMENTORS NOTE:
  2388. *
  2389. * There's an important subtlety in the front-end implementation of
  2390. * the timer interface. When a front end is given a `next' value,
  2391. * either returned from run_timers() or via timer_change_notify(),
  2392. * it should ensure that it really passes _that value_ as the `now'
  2393. * parameter to its next run_timers call. It should _not_ simply
  2394. * call GETTICKCOUNT() to get the `now' parameter when invoking
  2395. * run_timers().
  2396. *
  2397. * The reason for this is that an OS's system clock might not agree
  2398. * exactly with the timing mechanisms it supplies to wait for a
  2399. * given interval. I'll illustrate this by the simple example of
  2400. * Unix Plink, which uses timeouts to poll() in a way which for
  2401. * these purposes can simply be considered to be a wait() function.
  2402. * Suppose, for the sake of argument, that this wait() function
  2403. * tends to return early by 1%. Then a possible sequence of actions
  2404. * is:
  2405. *
  2406. * - run_timers() tells the front end that the next timer firing
  2407. * is 10000ms from now.
  2408. * - Front end calls wait(10000ms), but according to
  2409. * GETTICKCOUNT() it has only waited for 9900ms.
  2410. * - Front end calls run_timers() again, passing time T-100ms as
  2411. * `now'.
  2412. * - run_timers() does nothing, and says the next timer firing is
  2413. * still 100ms from now.
  2414. * - Front end calls wait(100ms), which only waits for 99ms.
  2415. * - Front end calls run_timers() yet again, passing time T-1ms.
  2416. * - run_timers() says there's still 1ms to wait.
  2417. * - Front end calls wait(1ms).
  2418. *
  2419. * If you're _lucky_ at this point, wait(1ms) will actually wait
  2420. * for 1ms and you'll only have woken the program up three times.
  2421. * If you're unlucky, wait(1ms) might do nothing at all due to
  2422. * being below some minimum threshold, and you might find your
  2423. * program spends the whole of the last millisecond tight-looping
  2424. * between wait() and run_timers().
  2425. *
  2426. * Instead, what you should do is to _save_ the precise `next'
  2427. * value provided by run_timers() or via timer_change_notify(), and
  2428. * use that precise value as the input to the next run_timers()
  2429. * call. So:
  2430. *
  2431. * - run_timers() tells the front end that the next timer firing
  2432. * is at time T, 10000ms from now.
  2433. * - Front end calls wait(10000ms).
  2434. * - Front end then immediately calls run_timers() and passes it
  2435. * time T, without stopping to check GETTICKCOUNT() at all.
  2436. *
  2437. * This guarantees that the program wakes up only as many times as
  2438. * there are actual timer actions to be taken, and that the timing
  2439. * mechanism will never send it into a tight loop.
  2440. *
  2441. * (It does also mean that the timer action in the above example
  2442. * will occur 100ms early, but this is not generally critical. And
  2443. * the hypothetical 1% error in wait() will be partially corrected
  2444. * for anyway when, _after_ run_timers() returns, you call
  2445. * GETTICKCOUNT() and compare the result with the returned `next'
  2446. * value to find out how long you have to make your next wait().)
  2447. */
  2448. typedef void (*timer_fn_t)(void *ctx, unsigned long now);
  2449. unsigned long schedule_timer(int ticks, timer_fn_t fn, void *ctx);
  2450. void expire_timer_context(void *ctx);
  2451. bool run_timers(unsigned long now, unsigned long *next);
  2452. void timer_change_notify(unsigned long next);
  2453. unsigned long timing_last_clock(void);
  2454. /*
  2455. * Exports from callback.c.
  2456. *
  2457. * This provides a method of queuing function calls to be run at the
  2458. * earliest convenience from the top-level event loop. Use it if
  2459. * you're deep in a nested chain of calls and want to trigger an
  2460. * action which will probably lead to your function being re-entered
  2461. * recursively if you just call the initiating function the normal
  2462. * way.
  2463. *
  2464. * Most front ends run the queued callbacks by simply calling
  2465. * run_toplevel_callbacks() after handling each event in their
  2466. * top-level event loop. However, if a front end doesn't have control
  2467. * over its own event loop (e.g. because it's using GTK) then it can
  2468. * instead request notifications when a callback is available, so that
  2469. * it knows to ask its delegate event loop to do the same thing. Also,
  2470. * if a front end needs to know whether a callback is pending without
  2471. * actually running it (e.g. so as to put a zero timeout on a poll()
  2472. * call) then it can call toplevel_callback_pending(), which will
  2473. * return true if at least one callback is in the queue.
  2474. *
  2475. * run_toplevel_callbacks() returns true if it ran any actual code.
  2476. * This can be used as a means of speculatively terminating a poll
  2477. * loop, as in PSFTP, for example - if a callback has run then perhaps
  2478. * it might have done whatever the loop's caller was waiting for.
  2479. */
  2480. void queue_toplevel_callback(toplevel_callback_fn_t fn, void *ctx);
  2481. bool run_toplevel_callbacks(void);
  2482. bool toplevel_callback_pending(void);
  2483. void delete_callbacks_for_context(void *ctx);
  2484. /*
  2485. * Another facility in callback.c deals with 'idempotent' callbacks,
  2486. * defined as those which never need to be scheduled again if they are
  2487. * already scheduled and have not yet run. (An example would be one
  2488. * which, when called, empties a queue of data completely: when data
  2489. * is added to the queue, you must ensure a run of the queue-consuming
  2490. * function has been scheduled, but if one is already pending, you
  2491. * don't need to schedule a second one.)
  2492. */
  2493. struct IdempotentCallback {
  2494. toplevel_callback_fn_t fn;
  2495. void *ctx;
  2496. bool queued;
  2497. };
  2498. void queue_idempotent_callback(struct IdempotentCallback *ic);
  2499. typedef void (*toplevel_callback_notify_fn_t)(void *ctx);
  2500. void request_callback_notifications(toplevel_callback_notify_fn_t notify,
  2501. void *ctx);
  2502. /*
  2503. * Facility provided by the platform to spawn a parallel subprocess
  2504. * and present its stdio via a Socket.
  2505. *
  2506. * 'prefix' indicates the prefix that should appear on messages passed
  2507. * to plug_log to provide stderr output from the process.
  2508. */
  2509. Socket *platform_start_subprocess(const char *cmd, Plug *plug,
  2510. const char *prefix);
  2511. /*
  2512. * Define no-op macros for the jump list functions, on platforms that
  2513. * don't support them. (This is a bit of a hack, and it'd be nicer to
  2514. * localise even the calls to those functions into the Windows front
  2515. * end, but it'll do for the moment.)
  2516. */
  2517. #ifndef JUMPLIST_SUPPORTED
  2518. #define add_session_to_jumplist(x) ((void)0)
  2519. #define remove_session_from_jumplist(x) ((void)0)
  2520. #endif
  2521. /* SURROGATE PAIR */
  2522. #ifndef HIGH_SURROGATE_START /* in some toolchains <winnls.h> defines these */
  2523. #define HIGH_SURROGATE_START 0xd800
  2524. #define HIGH_SURROGATE_END 0xdbff
  2525. #define LOW_SURROGATE_START 0xdc00
  2526. #define LOW_SURROGATE_END 0xdfff
  2527. #endif
  2528. /* REGIONAL INDICATOR SYMBOL LETTER A-Z */
  2529. #define IS_REGIONAL_INDICATOR_LETTER(wc) ((unsigned)(wc) - 0x1F1E6U < 26)
  2530. /* These macros exist in the Windows API, so the environment may
  2531. * provide them. If not, define them in terms of the above. */
  2532. #ifndef IS_HIGH_SURROGATE
  2533. #define IS_HIGH_SURROGATE(wch) (((wch) >= HIGH_SURROGATE_START) && \
  2534. ((wch) <= HIGH_SURROGATE_END))
  2535. #define IS_LOW_SURROGATE(wch) (((wch) >= LOW_SURROGATE_START) && \
  2536. ((wch) <= LOW_SURROGATE_END))
  2537. #define IS_SURROGATE_PAIR(hs, ls) (IS_HIGH_SURROGATE(hs) && \
  2538. IS_LOW_SURROGATE(ls))
  2539. #endif
  2540. #define IS_SURROGATE(wch) (((wch) >= HIGH_SURROGATE_START) && \
  2541. ((wch) <= LOW_SURROGATE_END))
  2542. #define HIGH_SURROGATE_OF(codept) \
  2543. (HIGH_SURROGATE_START + (((codept) - 0x10000) >> 10))
  2544. #define LOW_SURROGATE_OF(codept) \
  2545. (LOW_SURROGATE_START + (((codept) - 0x10000) & 0x3FF))
  2546. #define FROM_SURROGATES(wch1, wch2) \
  2547. (0x10000 + (((wch1) & 0x3FF) << 10) + ((wch2) & 0x3FF))
  2548. #endif