putty.h 116 KB

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