putty.h 119 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948
  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 "2021"
  21. #define PGP_MASTER_KEY_DETAILS "RSA, 3072-bit"
  22. #define PGP_MASTER_KEY_FP \
  23. "A872 D42F 1660 890F 0E05 223E DD43 55EA AC11 19DE"
  24. #define PGP_PREV_MASTER_KEY_YEAR "2018"
  25. #define PGP_PREV_MASTER_KEY_DETAILS "RSA, 4096-bit"
  26. #define PGP_PREV_MASTER_KEY_FP \
  27. "24E1 B1C5 75EA 3C9F F752 A922 76BC 7FE4 EBFD 2D9E"
  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 /* mouse wheel */
  334. } Mouse_Button;
  335. typedef enum {
  336. MA_NOTHING, MA_CLICK, MA_2CLK, MA_3CLK, MA_DRAG, MA_RELEASE
  337. } Mouse_Action;
  338. /* Keyboard modifiers -- keys the user is actually holding down */
  339. #define PKM_SHIFT 0x01
  340. #define PKM_CONTROL 0x02
  341. #define PKM_META 0x04
  342. #define PKM_ALT 0x08
  343. /* Keyboard flags that aren't really modifiers */
  344. #define PKF_CAPSLOCK 0x10
  345. #define PKF_NUMLOCK 0x20
  346. #define PKF_REPEAT 0x40
  347. /* Stand-alone keysyms for function keys */
  348. typedef enum {
  349. PK_NULL, /* No symbol for this key */
  350. /* Main keypad keys */
  351. PK_ESCAPE, PK_TAB, PK_BACKSPACE, PK_RETURN, PK_COMPOSE,
  352. /* Editing keys */
  353. PK_HOME, PK_INSERT, PK_DELETE, PK_END, PK_PAGEUP, PK_PAGEDOWN,
  354. /* Cursor keys */
  355. PK_UP, PK_DOWN, PK_RIGHT, PK_LEFT, PK_REST,
  356. /* Numeric keypad */ /* Real one looks like: */
  357. PK_PF1, PK_PF2, PK_PF3, PK_PF4, /* PF1 PF2 PF3 PF4 */
  358. PK_KPCOMMA, PK_KPMINUS, PK_KPDECIMAL, /* 7 8 9 - */
  359. PK_KP0, PK_KP1, PK_KP2, PK_KP3, PK_KP4, /* 4 5 6 , */
  360. PK_KP5, PK_KP6, PK_KP7, PK_KP8, PK_KP9, /* 1 2 3 en- */
  361. PK_KPBIGPLUS, PK_KPENTER, /* 0 . ter */
  362. /* Top row */
  363. PK_F1, PK_F2, PK_F3, PK_F4, PK_F5,
  364. PK_F6, PK_F7, PK_F8, PK_F9, PK_F10,
  365. PK_F11, PK_F12, PK_F13, PK_F14, PK_F15,
  366. PK_F16, PK_F17, PK_F18, PK_F19, PK_F20,
  367. PK_PAUSE
  368. } Key_Sym;
  369. #define PK_ISEDITING(k) ((k) >= PK_HOME && (k) <= PK_PAGEDOWN)
  370. #define PK_ISCURSOR(k) ((k) >= PK_UP && (k) <= PK_REST)
  371. #define PK_ISKEYPAD(k) ((k) >= PK_PF1 && (k) <= PK_KPENTER)
  372. #define PK_ISFKEY(k) ((k) >= PK_F1 && (k) <= PK_F20)
  373. enum {
  374. VT_XWINDOWS, VT_OEMANSI, VT_OEMONLY, VT_POORMAN, VT_UNICODE
  375. };
  376. enum {
  377. /*
  378. * SSH-2 key exchange algorithms
  379. */
  380. KEX_WARN,
  381. KEX_DHGROUP1,
  382. KEX_DHGROUP14,
  383. KEX_DHGROUP15,
  384. KEX_DHGROUP16,
  385. KEX_DHGROUP17,
  386. KEX_DHGROUP18,
  387. KEX_DHGEX,
  388. KEX_RSA,
  389. KEX_ECDH,
  390. KEX_NTRU_HYBRID,
  391. KEX_MAX
  392. };
  393. enum {
  394. /*
  395. * SSH-2 host key algorithms
  396. */
  397. HK_WARN,
  398. HK_RSA,
  399. HK_DSA,
  400. HK_ECDSA,
  401. HK_ED25519,
  402. HK_ED448,
  403. HK_MAX
  404. };
  405. enum {
  406. /*
  407. * SSH ciphers (both SSH-1 and SSH-2)
  408. */
  409. CIPHER_WARN, /* pseudo 'cipher' */
  410. CIPHER_3DES,
  411. CIPHER_BLOWFISH,
  412. CIPHER_AES, /* (SSH-2 only) */
  413. CIPHER_DES,
  414. CIPHER_ARCFOUR,
  415. CIPHER_CHACHA20,
  416. CIPHER_AESGCM,
  417. CIPHER_MAX /* no. ciphers (inc warn) */
  418. };
  419. enum TriState {
  420. /*
  421. * Several different bits of the PuTTY configuration seem to be
  422. * three-way settings whose values are `always yes', `always
  423. * no', and `decide by some more complex automated means'. This
  424. * is true of line discipline options (local echo and line
  425. * editing), proxy DNS, proxy terminal logging, Close On Exit, and
  426. * SSH server bug workarounds. Accordingly I supply a single enum
  427. * here to deal with them all.
  428. */
  429. FORCE_ON, FORCE_OFF, AUTO
  430. };
  431. enum {
  432. /*
  433. * Proxy types.
  434. */
  435. PROXY_NONE, PROXY_SOCKS4, PROXY_SOCKS5,
  436. PROXY_HTTP, PROXY_TELNET, PROXY_CMD, PROXY_SSH_TCPIP,
  437. PROXY_SSH_EXEC, PROXY_SSH_SUBSYSTEM,
  438. PROXY_FUZZ
  439. };
  440. enum {
  441. /*
  442. * Line discipline options which the backend might try to control.
  443. */
  444. LD_EDIT, /* local line editing */
  445. LD_ECHO, /* local echo */
  446. LD_N_OPTIONS
  447. };
  448. enum {
  449. /* Actions on remote window title query */
  450. TITLE_NONE, TITLE_EMPTY, TITLE_REAL
  451. };
  452. enum {
  453. /* SUPDUP character set options */
  454. SUPDUP_CHARSET_ASCII, SUPDUP_CHARSET_ITS, SUPDUP_CHARSET_WAITS
  455. };
  456. enum {
  457. /* Protocol back ends. (CONF_protocol) */
  458. PROT_RAW, PROT_TELNET, PROT_RLOGIN, PROT_SSH, PROT_SSHCONN,
  459. /* PROT_SERIAL is supported on a subset of platforms, but it doesn't
  460. * hurt to define it globally. */
  461. PROT_SERIAL,
  462. /* PROT_SUPDUP is the historical RFC 734 protocol. */
  463. PROT_SUPDUP,
  464. PROTOCOL_LIMIT, /* upper bound on number of protocols */
  465. };
  466. enum {
  467. /* Bell settings (CONF_beep) */
  468. BELL_DISABLED, BELL_DEFAULT, BELL_VISUAL, BELL_WAVEFILE, BELL_PCSPEAKER
  469. };
  470. enum {
  471. /* Taskbar flashing indication on bell (CONF_beep_ind) */
  472. B_IND_DISABLED, B_IND_FLASH, B_IND_STEADY
  473. };
  474. enum {
  475. /* Resize actions (CONF_resize_action) */
  476. RESIZE_TERM, RESIZE_DISABLED, RESIZE_FONT, RESIZE_EITHER
  477. };
  478. enum {
  479. /* Function key types (CONF_funky_type) */
  480. FUNKY_TILDE,
  481. FUNKY_LINUX,
  482. FUNKY_XTERM,
  483. FUNKY_VT400,
  484. FUNKY_VT100P,
  485. FUNKY_SCO,
  486. FUNKY_XTERM_216
  487. };
  488. enum {
  489. /* Shifted arrow key types (CONF_sharrow_type) */
  490. SHARROW_APPLICATION, /* Ctrl flips between ESC O A and ESC [ A */
  491. SHARROW_BITMAP /* ESC [ 1 ; n A, where n = 1 + bitmap of CAS */
  492. };
  493. enum {
  494. FQ_DEFAULT, FQ_ANTIALIASED, FQ_NONANTIALIASED, FQ_CLEARTYPE
  495. };
  496. enum {
  497. SER_PAR_NONE, SER_PAR_ODD, SER_PAR_EVEN, SER_PAR_MARK, SER_PAR_SPACE
  498. };
  499. enum {
  500. SER_FLOW_NONE, SER_FLOW_XONXOFF, SER_FLOW_RTSCTS, SER_FLOW_DSRDTR
  501. };
  502. /*
  503. * Tables of string <-> enum value mappings used in settings.c.
  504. * Defined here so that backends can export their GSS library tables
  505. * to the cross-platform settings code.
  506. */
  507. struct keyvalwhere {
  508. /*
  509. * Two fields which define a string and enum value to be
  510. * equivalent to each other.
  511. */
  512. const char *s;
  513. int v;
  514. /*
  515. * The next pair of fields are used by gprefs() in settings.c to
  516. * arrange that when it reads a list of strings representing a
  517. * preference list and translates it into the corresponding list
  518. * of integers, strings not appearing in the list are entered in a
  519. * configurable position rather than uniformly at the end.
  520. */
  521. /*
  522. * 'vrel' indicates which other value in the list to place this
  523. * element relative to. It should be a value that has occurred in
  524. * a 'v' field of some other element of the array, or -1 to
  525. * indicate that we simply place relative to one or other end of
  526. * the list.
  527. *
  528. * gprefs will try to process the elements in an order which makes
  529. * this field work (i.e. so that the element referenced has been
  530. * added before processing this one).
  531. */
  532. int vrel;
  533. /*
  534. * 'where' indicates whether to place the new value before or
  535. * after the one referred to by vrel. -1 means before; +1 means
  536. * after.
  537. *
  538. * When vrel is -1, this also implicitly indicates which end of
  539. * the array to use. So vrel=-1, where=-1 means to place _before_
  540. * some end of the list (hence, at the last element); vrel=-1,
  541. * where=+1 means to place _after_ an end (hence, at the first).
  542. */
  543. int where;
  544. };
  545. #ifndef NO_GSSAPI
  546. extern const int ngsslibs;
  547. extern const char *const gsslibnames[]; /* for displaying in configuration */
  548. extern const struct keyvalwhere gsslibkeywords[]; /* for settings.c */
  549. #endif
  550. extern const char *const ttymodes[];
  551. enum {
  552. /*
  553. * Network address types. Used for specifying choice of IPv4/v6
  554. * in config; also used in proxy.c to indicate whether a given
  555. * host name has already been resolved or will be resolved at
  556. * the proxy end.
  557. */
  558. ADDRTYPE_UNSPEC,
  559. ADDRTYPE_IPV4,
  560. ADDRTYPE_IPV6,
  561. ADDRTYPE_LOCAL, /* e.g. Unix domain socket, or Windows named pipe */
  562. ADDRTYPE_NAME /* SockAddr storing an unresolved host name */
  563. };
  564. /* Backend flags */
  565. #define BACKEND_RESIZE_FORBIDDEN 0x01 /* Backend does not allow
  566. resizing terminal */
  567. #define BACKEND_NEEDS_TERMINAL 0x02 /* Backend must have terminal */
  568. #define BACKEND_SUPPORTS_NC_HOST 0x04 /* Backend can honour
  569. CONF_ssh_nc_host */
  570. #define BACKEND_NOTIFIES_SESSION_START 0x08 /* Backend will call
  571. seat_notify_session_started */
  572. /* In (no)sshproxy.c */
  573. extern const bool ssh_proxy_supported;
  574. /*
  575. * This structure type wraps a Seat pointer, in a way that has no
  576. * purpose except to be a different type.
  577. *
  578. * The Seat wrapper functions that present interactive prompts all
  579. * expect one of these in place of their ordinary Seat pointer. You
  580. * get one by calling interactor_announce (defined below), which will
  581. * print a message (if not already done) identifying the Interactor
  582. * that originated the prompt.
  583. *
  584. * This arranges that the C type system itself will check that no call
  585. * to any of those Seat methods has omitted the mandatory call to
  586. * interactor_announce beforehand.
  587. */
  588. struct InteractionReadySeat {
  589. Seat *seat;
  590. };
  591. /*
  592. * The Interactor trait is implemented by anything that is capable of
  593. * presenting interactive prompts or questions to the user during
  594. * network connection setup. Every Backend that ever needs to do this
  595. * is an Interactor, but also, while a Backend is making its initial
  596. * network connection, it may go via network proxy code which is also
  597. * an Interactor and can ask questions of its own.
  598. */
  599. struct Interactor {
  600. const InteractorVtable *vt;
  601. /* The parent Interactor that we are a proxy for, if any. */
  602. Interactor *parent;
  603. /*
  604. * If we're the top-level Interactor (parent==NULL), then this
  605. * field records the last Interactor that actually did anything
  606. * interactive, so that we know when to announce a changeover
  607. * between levels of proxying.
  608. *
  609. * If parent != NULL, this field is not used.
  610. */
  611. Interactor *last_to_talk;
  612. };
  613. struct InteractorVtable {
  614. /*
  615. * Returns a user-facing description of the nature of the network
  616. * connection being made. Used in interactive proxy authentication
  617. * to announce which connection attempt is now in control of the
  618. * Seat.
  619. *
  620. * The idea is not just to be written in natural language, but to
  621. * connect with the user's idea of _why_ they think some
  622. * connection is being made. For example, instead of saying 'TCP
  623. * connection to 123.45.67.89 port 22', you might say 'SSH
  624. * connection to [logical host name for SSH host key purposes]'.
  625. *
  626. * The returned string must be freed by the caller.
  627. */
  628. char *(*description)(Interactor *itr);
  629. /*
  630. * Returns the LogPolicy associated with this Interactor. (A
  631. * Backend can derive this from its logging context; a proxy
  632. * Interactor inherits it from the Interactor for the parent
  633. * network connection.)
  634. */
  635. LogPolicy *(*logpolicy)(Interactor *itr);
  636. /*
  637. * Gets and sets the Seat that this Interactor talks to. When a
  638. * Seat is borrowed and replaced with a TempSeat, this will be the
  639. * mechanism by which that replacement happens.
  640. */
  641. Seat *(*get_seat)(Interactor *itr);
  642. void (*set_seat)(Interactor *itr, Seat *seat);
  643. };
  644. static inline char *interactor_description(Interactor *itr)
  645. { return itr->vt->description(itr); }
  646. static inline LogPolicy *interactor_logpolicy(Interactor *itr)
  647. { return itr->vt->logpolicy(itr); }
  648. static inline Seat *interactor_get_seat(Interactor *itr)
  649. { return itr->vt->get_seat(itr); }
  650. static inline void interactor_set_seat(Interactor *itr, Seat *seat)
  651. { itr->vt->set_seat(itr, seat); }
  652. static inline void interactor_set_child(Interactor *parent, Interactor *child)
  653. { child->parent = parent; }
  654. Seat *interactor_borrow_seat(Interactor *itr);
  655. void interactor_return_seat(Interactor *itr);
  656. InteractionReadySeat interactor_announce(Interactor *itr);
  657. /* Interactors that are Backends will find this helper function useful
  658. * in constructing their description strings */
  659. char *default_description(const BackendVtable *backvt,
  660. const char *host, int port);
  661. /*
  662. * The Backend trait is the top-level one that governs each of the
  663. * user-facing main modes that PuTTY can use to talk to some
  664. * destination: SSH, Telnet, serial port, pty, etc.
  665. */
  666. struct Backend {
  667. const BackendVtable *vt;
  668. /* Many Backends are also Interactors. If this one is, a pointer
  669. * to its Interactor trait lives here. */
  670. Interactor *interactor;
  671. };
  672. struct BackendVtable {
  673. char *(*init) (const BackendVtable *vt, Seat *seat,
  674. Backend **backend_out, LogContext *logctx, Conf *conf,
  675. const char *host, int port, char **realhost,
  676. bool nodelay, bool keepalive);
  677. void (*free) (Backend *be);
  678. /* Pass in a replacement configuration. */
  679. void (*reconfig) (Backend *be, Conf *conf);
  680. void (*send) (Backend *be, const char *buf, size_t len);
  681. /* sendbuffer() returns the current amount of buffered data */
  682. size_t (*sendbuffer) (Backend *be);
  683. void (*size) (Backend *be, int width, int height);
  684. void (*special) (Backend *be, SessionSpecialCode code, int arg);
  685. const SessionSpecial *(*get_specials) (Backend *be);
  686. bool (*connected) (Backend *be);
  687. int (*exitcode) (Backend *be);
  688. /* If back->sendok() returns false, the backend doesn't currently
  689. * want input data, so the frontend should avoid acquiring any if
  690. * possible (passing back-pressure on to its sender).
  691. *
  692. * Policy rule: no backend shall return true from sendok() while
  693. * its network connection attempt is still ongoing. This ensures
  694. * that if making the network connection involves a proxy type
  695. * which wants to interact with the user via the terminal, the
  696. * proxy implementation and the backend itself won't fight over
  697. * who gets the terminal input. */
  698. bool (*sendok) (Backend *be);
  699. bool (*ldisc_option_state) (Backend *be, int);
  700. void (*provide_ldisc) (Backend *be, Ldisc *ldisc);
  701. /* Tells the back end that the front end buffer is clearing. */
  702. void (*unthrottle) (Backend *be, size_t bufsize);
  703. int (*cfg_info) (Backend *be);
  704. /* Only implemented in the SSH protocol: check whether a
  705. * connection-sharing upstream exists for a given configuration. */
  706. bool (*test_for_upstream)(const char *host, int port, Conf *conf);
  707. /* Special-purpose function to return additional information to put
  708. * in a "are you sure you want to close this session" dialog;
  709. * return NULL if no such info, otherwise caller must free.
  710. * Only implemented in the SSH protocol, to warn about downstream
  711. * connections that would be lost if this one were terminated. */
  712. char *(*close_warn_text)(Backend *be);
  713. /* 'id' is a machine-readable name for the backend, used in
  714. * saved-session storage. 'displayname_tc' and 'displayname_lc'
  715. * are human-readable names, one in title-case for config boxes,
  716. * and one in lower-case for use in mid-sentence. */
  717. const char *id, *displayname_tc, *displayname_lc;
  718. int protocol;
  719. int default_port;
  720. unsigned flags;
  721. /* Only relevant for the serial protocol: bit masks of which
  722. * parity and flow control settings are supported. */
  723. unsigned serial_parity_mask, serial_flow_mask;
  724. };
  725. static inline char *backend_init(
  726. const BackendVtable *vt, Seat *seat, Backend **out, LogContext *logctx,
  727. Conf *conf, const char *host, int port, char **rhost, bool nd, bool ka)
  728. { return vt->init(vt, seat, out, logctx, conf, host, port, rhost, nd, ka); }
  729. static inline void backend_free(Backend *be)
  730. { be->vt->free(be); }
  731. static inline void backend_reconfig(Backend *be, Conf *conf)
  732. { be->vt->reconfig(be, conf); }
  733. static inline void backend_send(Backend *be, const char *buf, size_t len)
  734. { be->vt->send(be, buf, len); }
  735. static inline size_t backend_sendbuffer(Backend *be)
  736. { return be->vt->sendbuffer(be); }
  737. static inline void backend_size(Backend *be, int width, int height)
  738. { be->vt->size(be, width, height); }
  739. static inline void backend_special(
  740. Backend *be, SessionSpecialCode code, int arg)
  741. { be->vt->special(be, code, arg); }
  742. static inline const SessionSpecial *backend_get_specials(Backend *be)
  743. { return be->vt->get_specials(be); }
  744. static inline bool backend_connected(Backend *be)
  745. { return be->vt->connected(be); }
  746. static inline int backend_exitcode(Backend *be)
  747. { return be->vt->exitcode(be); }
  748. static inline bool backend_sendok(Backend *be)
  749. { return be->vt->sendok(be); }
  750. static inline bool backend_ldisc_option_state(Backend *be, int state)
  751. { return be->vt->ldisc_option_state(be, state); }
  752. static inline void backend_provide_ldisc(Backend *be, Ldisc *ldisc)
  753. { be->vt->provide_ldisc(be, ldisc); }
  754. static inline void backend_unthrottle(Backend *be, size_t bufsize)
  755. { be->vt->unthrottle(be, bufsize); }
  756. static inline int backend_cfg_info(Backend *be)
  757. { return be->vt->cfg_info(be); }
  758. extern const struct BackendVtable *const backends[];
  759. /*
  760. * In programs with a config UI, only the first few members of
  761. * backends[] will be displayed at the top-level; the others will be
  762. * relegated to a drop-down.
  763. */
  764. extern const size_t n_ui_backends;
  765. /*
  766. * Suggested default protocol provided by the backend link module.
  767. * The application is free to ignore this.
  768. */
  769. extern const int be_default_protocol;
  770. /*
  771. * Name of this particular application, for use in the config box
  772. * and other pieces of text.
  773. */
  774. extern const char *const appname;
  775. /*
  776. * Used by callback.c; declared up here so that prompts_t can use it
  777. */
  778. typedef void (*toplevel_callback_fn_t)(void *ctx);
  779. /* Enum of result types in SeatPromptResult below */
  780. typedef enum SeatPromptResultKind {
  781. /* Answer not yet available at all; either try again later or wait
  782. * for a callback (depending on the request's API) */
  783. SPRK_INCOMPLETE,
  784. /* We're abandoning the connection because the user interactively
  785. * told us to. (Hence, no need to present an error message
  786. * telling the user we're doing that: they already know.) */
  787. SPRK_USER_ABORT,
  788. /* We're abandoning the connection for some other reason (e.g. we
  789. * were unable to present the prompt at all, or a batch-mode
  790. * configuration told us to give the answer no). This may
  791. * ultimately have stemmed from some user configuration, but they
  792. * didn't _tell us right now_ to abandon this connection, so we
  793. * still need to inform them that we've done so. */
  794. SPRK_SW_ABORT,
  795. /* We're proceeding with the connection and have all requested
  796. * information (if any) */
  797. SPRK_OK
  798. } SeatPromptResultKind;
  799. /* Small struct to present the results of interactive requests from
  800. * backend to Seat (see below) */
  801. struct SeatPromptResult {
  802. SeatPromptResultKind kind;
  803. /*
  804. * In the case of SPRK_SW_ABORT, the frontend provides an error
  805. * message to present to the user. But dynamically allocating it
  806. * up front would mean having to make sure it got freed at any
  807. * call site where one of these structs is received (and freed
  808. * _once_ no matter how many times the struct is copied). So
  809. * instead we provide a function that will generate the error
  810. * message into a BinarySink.
  811. */
  812. void (*errfn)(SeatPromptResult, BinarySink *);
  813. /*
  814. * And some fields the error function can use to construct the
  815. * message (holding, e.g. an OS error code).
  816. */
  817. const char *errdata_lit; /* statically allocated, e.g. a string literal */
  818. unsigned errdata_u;
  819. };
  820. /* Helper function to construct the simple versions of these
  821. * structures inline */
  822. static inline SeatPromptResult make_spr_simple(SeatPromptResultKind kind)
  823. {
  824. SeatPromptResult spr;
  825. spr.kind = kind;
  826. spr.errdata_lit = NULL;
  827. return spr;
  828. }
  829. /* Most common constructor function for SPRK_SW_ABORT errors */
  830. SeatPromptResult make_spr_sw_abort_static(const char *);
  831. /* Convenience macros wrapping those constructors in turn */
  832. #define SPR_INCOMPLETE make_spr_simple(SPRK_INCOMPLETE)
  833. #define SPR_USER_ABORT make_spr_simple(SPRK_USER_ABORT)
  834. #define SPR_SW_ABORT(lit) make_spr_sw_abort_static(lit)
  835. #define SPR_OK make_spr_simple(SPRK_OK)
  836. /* Query function that folds both kinds of abort together */
  837. static inline bool spr_is_abort(SeatPromptResult spr)
  838. {
  839. return spr.kind == SPRK_USER_ABORT || spr.kind == SPRK_SW_ABORT;
  840. }
  841. /* Function to return a dynamically allocated copy of the error message */
  842. char *spr_get_error_message(SeatPromptResult spr);
  843. /*
  844. * Mechanism for getting text strings such as usernames and passwords
  845. * from the front-end.
  846. * The fields are mostly modelled after SSH's keyboard-interactive auth.
  847. * FIXME We should probably mandate a character set/encoding (probably UTF-8).
  848. *
  849. * Since many of the pieces of text involved may be chosen by the server,
  850. * the caller must take care to ensure that the server can't spoof locally-
  851. * generated prompts such as key passphrase prompts. Some ground rules:
  852. * - If the front-end needs to truncate a string, it should lop off the
  853. * end.
  854. * - The front-end should filter out any dangerous characters and
  855. * generally not trust the strings. (But \n is required to behave
  856. * vaguely sensibly, at least in `instruction', and ideally in
  857. * `prompt[]' too.)
  858. */
  859. typedef struct {
  860. char *prompt;
  861. bool echo;
  862. strbuf *result;
  863. } prompt_t;
  864. typedef struct prompts_t prompts_t;
  865. struct prompts_t {
  866. /*
  867. * Indicates whether the information entered is to be used locally
  868. * (for instance a key passphrase prompt), or is destined for the wire.
  869. * This is a hint only; the front-end is at liberty not to use this
  870. * information (so the caller should ensure that the supplied text is
  871. * sufficient).
  872. */
  873. bool to_server;
  874. /*
  875. * Indicates whether the prompts originated _at_ the server, so
  876. * that the front end can display some kind of trust sigil that
  877. * distinguishes (say) a legit private-key passphrase prompt from
  878. * a fake one sent by a malicious server.
  879. */
  880. bool from_server;
  881. char *name; /* Short description, perhaps for dialog box title */
  882. bool name_reqd; /* Display of `name' required or optional? */
  883. char *instruction; /* Long description, maybe with embedded newlines */
  884. bool instr_reqd; /* Display of `instruction' required or optional? */
  885. size_t n_prompts; /* May be zero (in which case display the foregoing,
  886. * if any, and return success) */
  887. size_t prompts_size; /* allocated storage capacity for prompts[] */
  888. prompt_t **prompts;
  889. void *data; /* slot for housekeeping data, managed by
  890. * seat_get_userpass_input(); initially NULL */
  891. SeatPromptResult spr; /* some implementations need to cache one of these */
  892. /*
  893. * Callback you can fill in to be notified when all the prompts'
  894. * responses are available. After you receive this notification, a
  895. * further call to the get_userpass_input function will return the
  896. * final state of the prompts system, which is guaranteed not to
  897. * be negative for 'still ongoing'.
  898. */
  899. toplevel_callback_fn_t callback;
  900. void *callback_ctx;
  901. /*
  902. * When this prompts_t is known to an Ldisc, we might need to
  903. * break the connection if things get freed in an emergency. So
  904. * this is a pointer to the Ldisc's pointer to us.
  905. */
  906. prompts_t **ldisc_ptr_to_us;
  907. };
  908. prompts_t *new_prompts(void);
  909. void add_prompt(prompts_t *p, char *promptstr, bool echo);
  910. void prompt_set_result(prompt_t *pr, const char *newstr);
  911. char *prompt_get_result(prompt_t *pr);
  912. const char *prompt_get_result_ref(prompt_t *pr);
  913. void free_prompts(prompts_t *p);
  914. /*
  915. * Data type definitions for true-colour terminal display.
  916. * 'optionalrgb' describes a single RGB colour, which overrides the
  917. * other colour settings if 'enabled' is nonzero, and is ignored
  918. * otherwise. 'truecolour' contains a pair of those for foreground and
  919. * background.
  920. */
  921. typedef struct optionalrgb {
  922. bool enabled;
  923. unsigned char r, g, b;
  924. } optionalrgb;
  925. extern const optionalrgb optionalrgb_none;
  926. typedef struct truecolour {
  927. optionalrgb fg, bg;
  928. } truecolour;
  929. #define optionalrgb_equal(r1,r2) ( \
  930. (r1).enabled==(r2).enabled && \
  931. (r1).r==(r2).r && (r1).g==(r2).g && (r1).b==(r2).b)
  932. #define truecolour_equal(c1,c2) ( \
  933. optionalrgb_equal((c1).fg, (c2).fg) && \
  934. optionalrgb_equal((c1).bg, (c2).bg))
  935. /*
  936. * Enumeration of clipboards. We provide some standard ones cross-
  937. * platform, and then permit each platform to extend this enumeration
  938. * further by defining PLATFORM_CLIPBOARDS in its own header file.
  939. *
  940. * CLIP_NULL is a non-clipboard, writes to which are ignored and reads
  941. * from which return no data.
  942. *
  943. * CLIP_LOCAL refers to a buffer within terminal.c, which
  944. * unconditionally saves the last data selected in the terminal. In
  945. * configurations where a system clipboard is not written
  946. * automatically on selection but instead by an explicit UI action,
  947. * this is where the code responding to that action can find the data
  948. * to write to the clipboard in question.
  949. */
  950. #define CROSS_PLATFORM_CLIPBOARDS(X) \
  951. X(CLIP_NULL, "null clipboard") \
  952. X(CLIP_LOCAL, "last text selected in terminal") \
  953. /* end of list */
  954. #define ALL_CLIPBOARDS(X) \
  955. CROSS_PLATFORM_CLIPBOARDS(X) \
  956. PLATFORM_CLIPBOARDS(X) \
  957. /* end of list */
  958. #define CLIP_ID(id,name) id,
  959. enum { ALL_CLIPBOARDS(CLIP_ID) N_CLIPBOARDS };
  960. #undef CLIP_ID
  961. /* Hint from backend to frontend about time-consuming operations, used
  962. * by seat_set_busy_status. Initial state is assumed to be
  963. * BUSY_NOT. */
  964. typedef enum BusyStatus {
  965. BUSY_NOT, /* Not busy, all user interaction OK */
  966. BUSY_WAITING, /* Waiting for something; local event loops still
  967. running so some local interaction (e.g. menus)
  968. OK, but network stuff is suspended */
  969. BUSY_CPU /* Locally busy (e.g. crypto); user interaction
  970. * suspended */
  971. } BusyStatus;
  972. typedef enum SeatInteractionContext {
  973. SIC_BANNER, SIC_KI_PROMPTS
  974. } SeatInteractionContext;
  975. typedef enum SeatOutputType {
  976. SEAT_OUTPUT_STDOUT, SEAT_OUTPUT_STDERR
  977. } SeatOutputType;
  978. typedef enum SeatDialogTextType {
  979. SDT_PARA, SDT_DISPLAY, SDT_SCARY_HEADING,
  980. SDT_TITLE, SDT_PROMPT, SDT_BATCH_ABORT,
  981. SDT_MORE_INFO_KEY, SDT_MORE_INFO_VALUE_SHORT, SDT_MORE_INFO_VALUE_BLOB
  982. } SeatDialogTextType;
  983. struct SeatDialogTextItem {
  984. SeatDialogTextType type;
  985. char *text;
  986. };
  987. struct SeatDialogText {
  988. size_t nitems, itemsize;
  989. SeatDialogTextItem *items;
  990. };
  991. SeatDialogText *seat_dialog_text_new(void);
  992. void seat_dialog_text_free(SeatDialogText *sdt);
  993. PRINTF_LIKE(3, 4) void seat_dialog_text_append(
  994. SeatDialogText *sdt, SeatDialogTextType type, const char *fmt, ...);
  995. /*
  996. * Data type 'Seat', which is an API intended to contain essentially
  997. * everything that a back end might need to talk to its client for:
  998. * session output, password prompts, SSH warnings about host keys and
  999. * weak cryptography, notifications of events like the remote process
  1000. * exiting or the GUI specials menu needing an update.
  1001. */
  1002. struct Seat {
  1003. const struct SeatVtable *vt;
  1004. };
  1005. struct SeatVtable {
  1006. /*
  1007. * Provide output from the remote session. 'type' indicates the
  1008. * type of the output (stdout or stderr), which can be used to
  1009. * split the output into separate message channels, if the seat
  1010. * wants to handle them differently. But combining the channels
  1011. * into one is OK too; that's what terminal-window based seats do.
  1012. *
  1013. * The return value is the current size of the output backlog.
  1014. */
  1015. size_t (*output)(Seat *seat, SeatOutputType type,
  1016. const void *data, size_t len);
  1017. /*
  1018. * Called when the back end wants to indicate that EOF has arrived
  1019. * on the server-to-client stream. Returns false to indicate that
  1020. * we intend to keep the session open in the other direction, or
  1021. * true to indicate that if they're closing so are we.
  1022. */
  1023. bool (*eof)(Seat *seat);
  1024. /*
  1025. * Called by the back end to notify that the output backlog has
  1026. * changed size. A front end in control of the event loop won't
  1027. * necessarily need this (they can just keep checking it via
  1028. * backend_sendbuffer at every opportunity), but one buried in the
  1029. * depths of something else (like an SSH proxy) will need to be
  1030. * proactively notified that the amount of buffered data has
  1031. * become smaller.
  1032. */
  1033. void (*sent)(Seat *seat, size_t new_sendbuffer);
  1034. /*
  1035. * Provide authentication-banner output from the session setup.
  1036. * End-user Seats can treat this as very similar to 'output', but
  1037. * intermediate Seats in complex proxying situations will want to
  1038. * implement this and 'output' differently.
  1039. */
  1040. size_t (*banner)(Seat *seat, const void *data, size_t len);
  1041. /*
  1042. * Try to get answers from a set of interactive login prompts. The
  1043. * prompts are provided in 'p'.
  1044. *
  1045. * (FIXME: it would be nice to distinguish two classes of user-
  1046. * abort action, so the user could specify 'I want to abandon this
  1047. * entire attempt to start a session' or the milder 'I want to
  1048. * abandon this particular form of authentication and fall back to
  1049. * a different one' - e.g. if you turn out not to be able to
  1050. * remember your private key passphrase then perhaps you'd rather
  1051. * fall back to password auth rather than aborting the whole
  1052. * session.)
  1053. */
  1054. SeatPromptResult (*get_userpass_input)(Seat *seat, prompts_t *p);
  1055. /*
  1056. * Notify the seat that the main session channel has been
  1057. * successfully set up.
  1058. *
  1059. * This is only used as part of the SSH proxying system, so it's
  1060. * not necessary to implement it in all backends. A backend must
  1061. * call this if it advertises the BACKEND_NOTIFIES_SESSION_START
  1062. * flag, and otherwise, doesn't have to.
  1063. */
  1064. void (*notify_session_started)(Seat *seat);
  1065. /*
  1066. * Notify the seat that the process running at the other end of
  1067. * the connection has finished.
  1068. */
  1069. void (*notify_remote_exit)(Seat *seat);
  1070. /*
  1071. * Notify the seat that the whole connection has finished.
  1072. * (Distinct from notify_remote_exit, e.g. in the case where you
  1073. * have port forwardings still active when the main foreground
  1074. * session goes away: then you'd get notify_remote_exit when the
  1075. * foreground session dies, but notify_remote_disconnect when the
  1076. * last forwarding vanishes and the network connection actually
  1077. * closes.)
  1078. *
  1079. * This function might be called multiple times by accident; seats
  1080. * should be prepared to cope.
  1081. *
  1082. * More precisely: this function notifies the seat that
  1083. * backend_connected() might now return false where previously it
  1084. * returned true. (Note the 'might': an accidental duplicate call
  1085. * might happen when backend_connected() was already returning
  1086. * false. Or even, in weird situations, when it hadn't stopped
  1087. * returning true yet. The point is, when you get this
  1088. * notification, all it's really telling you is that it's worth
  1089. * _checking_ backend_connected, if you weren't already.)
  1090. */
  1091. void (*notify_remote_disconnect)(Seat *seat);
  1092. /*
  1093. * Notify the seat that the connection has suffered a fatal error.
  1094. */
  1095. void (*connection_fatal)(Seat *seat, const char *message);
  1096. /*
  1097. * Notify the seat that the list of special commands available
  1098. * from backend_get_specials() has changed, so that it might want
  1099. * to call that function to repopulate its menu.
  1100. *
  1101. * Seats are not expected to call backend_get_specials()
  1102. * proactively; they may start by assuming that the backend
  1103. * provides no special commands at all, so if the backend does
  1104. * provide any, then it should use this notification at startup
  1105. * time. Of course it can also invoke it later if the set of
  1106. * special commands changes.
  1107. *
  1108. * It does not need to invoke it at session shutdown.
  1109. */
  1110. void (*update_specials_menu)(Seat *seat);
  1111. /*
  1112. * Get the seat's preferred value for an SSH terminal mode
  1113. * setting. Returning NULL indicates no preference (i.e. the SSH
  1114. * connection will not attempt to set the mode at all).
  1115. *
  1116. * The returned value is dynamically allocated, and the caller
  1117. * should free it.
  1118. */
  1119. char *(*get_ttymode)(Seat *seat, const char *mode);
  1120. /*
  1121. * Tell the seat whether the backend is currently doing anything
  1122. * CPU-intensive (typically a cryptographic key exchange). See
  1123. * BusyStatus enumeration above.
  1124. */
  1125. void (*set_busy_status)(Seat *seat, BusyStatus status);
  1126. /*
  1127. * Ask the seat whether a given SSH host key should be accepted.
  1128. * This is called after we've already checked it by any means we
  1129. * can do ourselves, such as checking against host key
  1130. * fingerprints in the Conf or the host key cache on disk: once we
  1131. * call this function, we've already decided there's nothing for
  1132. * it but to prompt the user.
  1133. *
  1134. * 'mismatch' reports the result of checking the host key cache:
  1135. * it is true if the server has presented a host key different
  1136. * from the one we expected, and false if we had no expectation in
  1137. * the first place.
  1138. *
  1139. * This call may prompt the user synchronously and not return
  1140. * until the answer is available, or it may present the prompt and
  1141. * return immediately, giving the answer later via the provided
  1142. * callback.
  1143. *
  1144. * Return values:
  1145. *
  1146. * - +1 means `user approved the key, so continue with the
  1147. * connection'
  1148. *
  1149. * - 0 means `user rejected the key, abandon the connection'
  1150. *
  1151. * - -1 means `I've initiated enquiries, please wait to be called
  1152. * back via the provided function with a result that's either 0
  1153. * or +1'.
  1154. */
  1155. SeatPromptResult (*confirm_ssh_host_key)(
  1156. Seat *seat, const char *host, int port, const char *keytype,
  1157. char *keystr, SeatDialogText *text, HelpCtx helpctx,
  1158. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1159. /*
  1160. * Check with the seat whether it's OK to use a cryptographic
  1161. * primitive from below the 'warn below this line' threshold in
  1162. * the input Conf. Return values are the same as
  1163. * confirm_ssh_host_key above.
  1164. */
  1165. SeatPromptResult (*confirm_weak_crypto_primitive)(
  1166. Seat *seat, const char *algtype, const char *algname,
  1167. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1168. /*
  1169. * Variant form of confirm_weak_crypto_primitive, which prints a
  1170. * slightly different message but otherwise has the same
  1171. * semantics.
  1172. *
  1173. * This form is used in the case where we're using a host key
  1174. * below the warning threshold because that's the best one we have
  1175. * cached, but at least one host key algorithm *above* the
  1176. * threshold is available that we don't have cached. 'betteralgs'
  1177. * lists the better algorithm(s).
  1178. */
  1179. SeatPromptResult (*confirm_weak_cached_hostkey)(
  1180. Seat *seat, const char *algname, const char *betteralgs,
  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, const char *atyp, const char *aname,
  1303. void (*cb)(void *ctx, SeatPromptResult result), void *ctx)
  1304. { return iseat.seat->vt->confirm_weak_crypto_primitive(
  1305. iseat.seat, atyp, aname, cb, ctx); }
  1306. static inline SeatPromptResult seat_confirm_weak_cached_hostkey(
  1307. InteractionReadySeat iseat, const char *aname, const char *better,
  1308. void (*cb)(void *ctx, SeatPromptResult result), void *ctx)
  1309. { return iseat.seat->vt->confirm_weak_cached_hostkey(
  1310. iseat.seat, aname, better, 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. };
  1360. /* In the utils subdir: print a message to the Seat which can't be
  1361. * spoofed by server-supplied auth-time output such as SSH banners */
  1362. void seat_antispoof_msg(InteractionReadySeat iseat, const char *msg);
  1363. /*
  1364. * Stub methods for seat implementations that want to use the obvious
  1365. * null handling for a given method.
  1366. *
  1367. * These are generally obvious, except for is_utf8, where you might
  1368. * plausibly want to return either fixed answer 'no' or 'yes'.
  1369. */
  1370. size_t nullseat_output(
  1371. Seat *seat, SeatOutputType type, const void *data, size_t len);
  1372. bool nullseat_eof(Seat *seat);
  1373. void nullseat_sent(Seat *seat, size_t bufsize);
  1374. size_t nullseat_banner(Seat *seat, const void *data, size_t len);
  1375. size_t nullseat_banner_to_stderr(Seat *seat, const void *data, size_t len);
  1376. SeatPromptResult nullseat_get_userpass_input(Seat *seat, prompts_t *p);
  1377. void nullseat_notify_session_started(Seat *seat);
  1378. void nullseat_notify_remote_exit(Seat *seat);
  1379. void nullseat_notify_remote_disconnect(Seat *seat);
  1380. void nullseat_connection_fatal(Seat *seat, const char *message);
  1381. void nullseat_update_specials_menu(Seat *seat);
  1382. char *nullseat_get_ttymode(Seat *seat, const char *mode);
  1383. void nullseat_set_busy_status(Seat *seat, BusyStatus status);
  1384. SeatPromptResult nullseat_confirm_ssh_host_key(
  1385. Seat *seat, const char *host, int port, const char *keytype,
  1386. char *keystr, SeatDialogText *text, HelpCtx helpctx,
  1387. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1388. SeatPromptResult nullseat_confirm_weak_crypto_primitive(
  1389. Seat *seat, const char *algtype, const char *algname,
  1390. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1391. SeatPromptResult nullseat_confirm_weak_cached_hostkey(
  1392. Seat *seat, const char *algname, const char *betteralgs,
  1393. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1394. const SeatDialogPromptDescriptions *nullseat_prompt_descriptions(Seat *seat);
  1395. bool nullseat_is_never_utf8(Seat *seat);
  1396. bool nullseat_is_always_utf8(Seat *seat);
  1397. void nullseat_echoedit_update(Seat *seat, bool echoing, bool editing);
  1398. const char *nullseat_get_x_display(Seat *seat);
  1399. bool nullseat_get_windowid(Seat *seat, long *id_out);
  1400. bool nullseat_get_window_pixel_size(Seat *seat, int *width, int *height);
  1401. StripCtrlChars *nullseat_stripctrl_new(
  1402. Seat *seat, BinarySink *bs_out, SeatInteractionContext sic);
  1403. void nullseat_set_trust_status(Seat *seat, bool trusted);
  1404. bool nullseat_can_set_trust_status_yes(Seat *seat);
  1405. bool nullseat_can_set_trust_status_no(Seat *seat);
  1406. bool nullseat_has_mixed_input_stream_yes(Seat *seat);
  1407. bool nullseat_has_mixed_input_stream_no(Seat *seat);
  1408. bool nullseat_verbose_no(Seat *seat);
  1409. bool nullseat_verbose_yes(Seat *seat);
  1410. bool nullseat_interactive_no(Seat *seat);
  1411. bool nullseat_interactive_yes(Seat *seat);
  1412. bool nullseat_get_cursor_position(Seat *seat, int *x, int *y);
  1413. /*
  1414. * Seat functions provided by the platform's console-application
  1415. * support module (console.c in each platform subdirectory).
  1416. */
  1417. void console_connection_fatal(Seat *seat, const char *message);
  1418. SeatPromptResult console_confirm_ssh_host_key(
  1419. Seat *seat, const char *host, int port, const char *keytype,
  1420. char *keystr, SeatDialogText *text, HelpCtx helpctx,
  1421. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1422. SeatPromptResult console_confirm_weak_crypto_primitive(
  1423. Seat *seat, const char *algtype, const char *algname,
  1424. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1425. SeatPromptResult console_confirm_weak_cached_hostkey(
  1426. Seat *seat, const char *algname, const char *betteralgs,
  1427. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1428. StripCtrlChars *console_stripctrl_new(
  1429. Seat *seat, BinarySink *bs_out, SeatInteractionContext sic);
  1430. void console_set_trust_status(Seat *seat, bool trusted);
  1431. bool console_can_set_trust_status(Seat *seat);
  1432. bool console_has_mixed_input_stream(Seat *seat);
  1433. const SeatDialogPromptDescriptions *console_prompt_descriptions(Seat *seat);
  1434. /*
  1435. * Other centralised seat functions.
  1436. */
  1437. SeatPromptResult filexfer_get_userpass_input(Seat *seat, prompts_t *p);
  1438. bool cmdline_seat_verbose(Seat *seat);
  1439. /*
  1440. * TempSeat: a seat implementation that can be given to a backend
  1441. * temporarily while network proxy setup is using the real seat.
  1442. * Buffers output and trust-status changes until the real seat is
  1443. * available again.
  1444. */
  1445. /* Called by the proxy code to make a TempSeat. */
  1446. Seat *tempseat_new(Seat *real);
  1447. /* Query functions to tell if a Seat _is_ temporary, and if so, to
  1448. * return the underlying real Seat. */
  1449. bool is_tempseat(Seat *seat);
  1450. Seat *tempseat_get_real(Seat *seat);
  1451. /* Called by interactor_return_seat once the proxy connection has
  1452. * finished setting up (or failed), to pass on any buffered stuff to
  1453. * the real seat. */
  1454. void tempseat_flush(Seat *ts);
  1455. /* Frees a TempSeat, without flushing anything it has buffered. (Call
  1456. * this after tempseat_flush, or alternatively, when you were going to
  1457. * abandon the whole connection anyway.) */
  1458. void tempseat_free(Seat *ts);
  1459. typedef struct rgb {
  1460. uint8_t r, g, b;
  1461. } rgb;
  1462. /*
  1463. * Data type 'TermWin', which is a vtable encapsulating all the
  1464. * functionality that Terminal expects from its containing terminal
  1465. * window.
  1466. */
  1467. struct TermWin {
  1468. const struct TermWinVtable *vt;
  1469. };
  1470. struct TermWinVtable {
  1471. /*
  1472. * All functions listed here between setup_draw_ctx and
  1473. * free_draw_ctx expect to be _called_ between them too, so that
  1474. * the TermWin has a drawing context currently available.
  1475. *
  1476. * (Yes, even char_width, because e.g. the Windows implementation
  1477. * of TermWin handles it by loading the currently configured font
  1478. * into the HDC and doing a GDI query.)
  1479. */
  1480. bool (*setup_draw_ctx)(TermWin *);
  1481. /* Draw text in the window, during a painting operation */
  1482. void (*draw_text)(TermWin *, int x, int y, wchar_t *text, int len,
  1483. unsigned long attrs, int line_attrs, truecolour tc);
  1484. /* Draw the visible cursor. Expects you to have called do_text
  1485. * first (because it might just draw an underline over a character
  1486. * presumed to exist already), but also expects you to pass in all
  1487. * the details of the character under the cursor (because it might
  1488. * redraw it in different colours). */
  1489. void (*draw_cursor)(TermWin *, int x, int y, wchar_t *text, int len,
  1490. unsigned long attrs, int line_attrs, truecolour tc);
  1491. /* Draw the sigil indicating that a line of text has come from
  1492. * PuTTY itself rather than the far end (defence against end-of-
  1493. * authentication spoofing) */
  1494. void (*draw_trust_sigil)(TermWin *, int x, int y);
  1495. int (*char_width)(TermWin *, int uc);
  1496. void (*free_draw_ctx)(TermWin *);
  1497. void (*set_cursor_pos)(TermWin *, int x, int y);
  1498. /* set_raw_mouse_mode instructs the front end to start sending mouse events
  1499. * in raw mode suitable for translating into mouse-tracking terminal data
  1500. * (e.g. include scroll-wheel events and don't bother to identify double-
  1501. * and triple-clicks). set_raw_mouse_mode_pointer instructs the front end
  1502. * to change the mouse pointer shape to *indicate* raw mouse mode. */
  1503. void (*set_raw_mouse_mode)(TermWin *, bool enable);
  1504. void (*set_raw_mouse_mode_pointer)(TermWin *, bool enable);
  1505. void (*set_scrollbar)(TermWin *, int total, int start, int page);
  1506. void (*bell)(TermWin *, int mode);
  1507. void (*clip_write)(TermWin *, int clipboard, wchar_t *text, int *attrs,
  1508. truecolour *colours, int len, bool must_deselect);
  1509. void (*clip_request_paste)(TermWin *, int clipboard);
  1510. void (*refresh)(TermWin *);
  1511. /* request_resize asks the front end if the terminal can please be
  1512. * resized to (w,h) in characters. The front end MAY call
  1513. * term_size() in response to tell the terminal its new size
  1514. * (which MAY be the requested size, or some other size if the
  1515. * requested one can't be achieved). The front end MAY also not
  1516. * call term_size() at all. But the front end MUST reply to this
  1517. * request by calling term_resize_request_completed(), after the
  1518. * responding resize event has taken place (if any).
  1519. *
  1520. * The calls to term_size and term_resize_request_completed may be
  1521. * synchronous callbacks from within the call to request_resize(). */
  1522. void (*request_resize)(TermWin *, int w, int h);
  1523. void (*set_title)(TermWin *, const char *title, int codepage);
  1524. void (*set_icon_title)(TermWin *, const char *icontitle, int codepage);
  1525. /* set_minimised and set_maximised are assumed to set two
  1526. * independent settings, rather than a single three-way
  1527. * {min,normal,max} switch. The idea is that when you un-minimise
  1528. * the window it remembers whether to go back to normal or
  1529. * maximised. */
  1530. void (*set_minimised)(TermWin *, bool minimised);
  1531. void (*set_maximised)(TermWin *, bool maximised);
  1532. void (*move)(TermWin *, int x, int y);
  1533. void (*set_zorder)(TermWin *, bool top);
  1534. /* Set the colour palette that the TermWin will use to display
  1535. * text. One call to this function sets 'ncolours' consecutive
  1536. * colours in the OSC 4 sequence, starting at 'start'. */
  1537. void (*palette_set)(TermWin *, unsigned start, unsigned ncolours,
  1538. const rgb *colours);
  1539. /* Query the front end for any OS-local overrides to the default
  1540. * colours stored in Conf. The front end should set any it cares
  1541. * about by calling term_palette_override.
  1542. *
  1543. * The Terminal object is passed in as a parameter, because this
  1544. * can be called as a callback from term_init(). So the TermWin
  1545. * itself won't yet have been told where to find its Terminal
  1546. * object, because that doesn't happen until term_init
  1547. * returns. */
  1548. void (*palette_get_overrides)(TermWin *, Terminal *);
  1549. /* Notify the front end that the terminal's buffer of unprocessed
  1550. * output has reduced. (Front ends will likely pass this straight
  1551. * on to backend_unthrottle.) */
  1552. void (*unthrottle)(TermWin *, size_t bufsize);
  1553. };
  1554. static inline bool win_setup_draw_ctx(TermWin *win)
  1555. { return win->vt->setup_draw_ctx(win); }
  1556. static inline void win_draw_text(
  1557. TermWin *win, int x, int y, wchar_t *text, int len,
  1558. unsigned long attrs, int line_attrs, truecolour tc)
  1559. { win->vt->draw_text(win, x, y, text, len, attrs, line_attrs, tc); }
  1560. static inline void win_draw_cursor(
  1561. TermWin *win, int x, int y, wchar_t *text, int len,
  1562. unsigned long attrs, int line_attrs, truecolour tc)
  1563. { win->vt->draw_cursor(win, x, y, text, len, attrs, line_attrs, tc); }
  1564. static inline void win_draw_trust_sigil(TermWin *win, int x, int y)
  1565. { win->vt->draw_trust_sigil(win, x, y); }
  1566. static inline int win_char_width(TermWin *win, int uc)
  1567. { return win->vt->char_width(win, uc); }
  1568. static inline void win_free_draw_ctx(TermWin *win)
  1569. { win->vt->free_draw_ctx(win); }
  1570. static inline void win_set_cursor_pos(TermWin *win, int x, int y)
  1571. { win->vt->set_cursor_pos(win, x, y); }
  1572. static inline void win_set_raw_mouse_mode(TermWin *win, bool enable)
  1573. { win->vt->set_raw_mouse_mode(win, enable); }
  1574. static inline void win_set_raw_mouse_mode_pointer(TermWin *win, bool enable)
  1575. { win->vt->set_raw_mouse_mode_pointer(win, enable); }
  1576. static inline void win_set_scrollbar(TermWin *win, int t, int s, int p)
  1577. { win->vt->set_scrollbar(win, t, s, p); }
  1578. static inline void win_bell(TermWin *win, int mode)
  1579. { win->vt->bell(win, mode); }
  1580. static inline void win_clip_write(
  1581. TermWin *win, int clipboard, wchar_t *text, int *attrs,
  1582. truecolour *colours, int len, bool deselect)
  1583. { win->vt->clip_write(win, clipboard, text, attrs, colours, len, deselect); }
  1584. static inline void win_clip_request_paste(TermWin *win, int clipboard)
  1585. { win->vt->clip_request_paste(win, clipboard); }
  1586. static inline void win_refresh(TermWin *win)
  1587. { win->vt->refresh(win); }
  1588. static inline void win_request_resize(TermWin *win, int w, int h)
  1589. { win->vt->request_resize(win, w, h); }
  1590. static inline void win_set_title(TermWin *win, const char *title, int codepage)
  1591. { win->vt->set_title(win, title, codepage); }
  1592. static inline void win_set_icon_title(TermWin *win, const char *icontitle,
  1593. int codepage)
  1594. { win->vt->set_icon_title(win, icontitle, codepage); }
  1595. static inline void win_set_minimised(TermWin *win, bool minimised)
  1596. { win->vt->set_minimised(win, minimised); }
  1597. static inline void win_set_maximised(TermWin *win, bool maximised)
  1598. { win->vt->set_maximised(win, maximised); }
  1599. static inline void win_move(TermWin *win, int x, int y)
  1600. { win->vt->move(win, x, y); }
  1601. static inline void win_set_zorder(TermWin *win, bool top)
  1602. { win->vt->set_zorder(win, top); }
  1603. static inline void win_palette_set(
  1604. TermWin *win, unsigned start, unsigned ncolours, const rgb *colours)
  1605. { win->vt->palette_set(win, start, ncolours, colours); }
  1606. static inline void win_palette_get_overrides(TermWin *win, Terminal *term)
  1607. { win->vt->palette_get_overrides(win, term); }
  1608. static inline void win_unthrottle(TermWin *win, size_t size)
  1609. { win->vt->unthrottle(win, size); }
  1610. /*
  1611. * Global functions not specific to a connection instance.
  1612. */
  1613. void nonfatal(const char *, ...) PRINTF_LIKE(1, 2);
  1614. NORETURN void modalfatalbox(const char *, ...) PRINTF_LIKE(1, 2);
  1615. NORETURN void cleanup_exit(int);
  1616. /*
  1617. * Exports from conf.c, and a big enum (via parametric macro) of
  1618. * configuration option keys.
  1619. */
  1620. #define CONFIG_OPTIONS(X) \
  1621. /* X(value-type, subkey-type, keyword) */ \
  1622. X(STR, NONE, host) \
  1623. X(INT, NONE, port) \
  1624. X(INT, NONE, protocol) /* PROT_SSH, PROT_TELNET etc */ \
  1625. X(INT, NONE, addressfamily) /* ADDRTYPE_IPV[46] or ADDRTYPE_UNSPEC */ \
  1626. X(INT, NONE, close_on_exit) /* FORCE_ON, FORCE_OFF, AUTO */ \
  1627. X(BOOL, NONE, warn_on_close) \
  1628. X(INT, NONE, ping_interval) /* in seconds */ \
  1629. X(BOOL, NONE, tcp_nodelay) \
  1630. X(BOOL, NONE, tcp_keepalives) \
  1631. X(STR, NONE, loghost) /* logical host being contacted, for host key check */ \
  1632. /* Proxy options */ \
  1633. X(STR, NONE, proxy_exclude_list) \
  1634. X(INT, NONE, proxy_dns) /* FORCE_ON, FORCE_OFF, AUTO */ \
  1635. X(BOOL, NONE, even_proxy_localhost) \
  1636. X(INT, NONE, proxy_type) /* PROXY_NONE, PROXY_SOCKS4, ... */ \
  1637. X(STR, NONE, proxy_host) \
  1638. X(INT, NONE, proxy_port) \
  1639. X(STR, NONE, proxy_username) \
  1640. X(STR, NONE, proxy_password) \
  1641. X(STR, NONE, proxy_telnet_command) \
  1642. X(INT, NONE, proxy_log_to_term) /* FORCE_ON, FORCE_OFF, AUTO */ \
  1643. /* SSH options */ \
  1644. X(STR, NONE, remote_cmd) \
  1645. X(STR, NONE, remote_cmd2) /* fallback if remote_cmd fails; never loaded or saved */ \
  1646. X(BOOL, NONE, nopty) \
  1647. X(BOOL, NONE, compression) \
  1648. X(INT, INT, ssh_kexlist) \
  1649. X(INT, INT, ssh_hklist) \
  1650. X(BOOL, NONE, ssh_prefer_known_hostkeys) \
  1651. X(INT, NONE, ssh_rekey_time) /* in minutes */ \
  1652. X(STR, NONE, ssh_rekey_data) /* string encoding e.g. "100K", "2M", "1G" */ \
  1653. X(BOOL, NONE, tryagent) \
  1654. X(BOOL, NONE, agentfwd) \
  1655. X(BOOL, NONE, change_username) /* allow username switching in SSH-2 */ \
  1656. X(INT, INT, ssh_cipherlist) \
  1657. X(FILENAME, NONE, keyfile) \
  1658. X(FILENAME, NONE, detached_cert) \
  1659. X(STR, NONE, auth_plugin) \
  1660. /* \
  1661. * Which SSH protocol to use. \
  1662. * For historical reasons, the current legal values for CONF_sshprot \
  1663. * are: \
  1664. * 0 = SSH-1 only \
  1665. * 3 = SSH-2 only \
  1666. * We used to also support \
  1667. * 1 = SSH-1 with fallback to SSH-2 \
  1668. * 2 = SSH-2 with fallback to SSH-1 \
  1669. * and we continue to use 0/3 in storage formats rather than the more \
  1670. * obvious 1/2 to avoid surprises if someone saves a session and later \
  1671. * downgrades PuTTY. So it's easier to use these numbers internally too. \
  1672. */ \
  1673. X(INT, NONE, sshprot) \
  1674. X(BOOL, NONE, ssh2_des_cbc) /* "des-cbc" unrecommended SSH-2 cipher */ \
  1675. X(BOOL, NONE, ssh_no_userauth) /* bypass "ssh-userauth" (SSH-2 only) */ \
  1676. X(BOOL, NONE, ssh_no_trivial_userauth) /* disable trivial types of auth */ \
  1677. X(BOOL, NONE, ssh_show_banner) /* show USERAUTH_BANNERs (SSH-2 only) */ \
  1678. X(BOOL, NONE, try_tis_auth) \
  1679. X(BOOL, NONE, try_ki_auth) \
  1680. X(BOOL, NONE, try_gssapi_auth) /* attempt gssapi auth via ssh userauth */ \
  1681. X(BOOL, NONE, try_gssapi_kex) /* attempt gssapi auth via ssh kex */ \
  1682. X(BOOL, NONE, gssapifwd) /* forward tgt via gss */ \
  1683. X(INT, NONE, gssapirekey) /* KEXGSS refresh interval (mins) */ \
  1684. X(INT, INT, ssh_gsslist) /* preference order for local GSS libs */ \
  1685. X(FILENAME, NONE, ssh_gss_custom) \
  1686. X(BOOL, NONE, ssh_subsys) /* run a subsystem rather than a command */ \
  1687. X(BOOL, NONE, ssh_subsys2) /* fallback to go with remote_cmd_ptr2 */ \
  1688. X(BOOL, NONE, ssh_no_shell) /* avoid running a shell */ \
  1689. X(STR, NONE, ssh_nc_host) /* host to connect to in `nc' mode */ \
  1690. X(INT, NONE, ssh_nc_port) /* port to connect to in `nc' mode */ \
  1691. /* Telnet options */ \
  1692. X(STR, NONE, termtype) \
  1693. X(STR, NONE, termspeed) \
  1694. X(STR, STR, ttymodes) /* values are "Vvalue" or "A" */ \
  1695. X(STR, STR, environmt) \
  1696. X(STR, NONE, username) \
  1697. X(BOOL, NONE, username_from_env) \
  1698. X(STR, NONE, localusername) \
  1699. X(BOOL, NONE, rfc_environ) \
  1700. X(BOOL, NONE, passive_telnet) \
  1701. /* Serial port options */ \
  1702. X(STR, NONE, serline) \
  1703. X(INT, NONE, serspeed) \
  1704. X(INT, NONE, serdatabits) \
  1705. X(INT, NONE, serstopbits) \
  1706. X(INT, NONE, serparity) /* SER_PAR_NONE, SER_PAR_ODD, ... */ \
  1707. X(INT, NONE, serflow) /* SER_FLOW_NONE, SER_FLOW_XONXOFF, ... */ \
  1708. /* Supdup options */ \
  1709. X(STR, NONE, supdup_location) \
  1710. X(INT, NONE, supdup_ascii_set) \
  1711. X(BOOL, NONE, supdup_more) \
  1712. X(BOOL, NONE, supdup_scroll) \
  1713. /* Keyboard options */ \
  1714. X(BOOL, NONE, bksp_is_delete) \
  1715. X(BOOL, NONE, rxvt_homeend) \
  1716. X(INT, NONE, funky_type) /* FUNKY_XTERM, FUNKY_LINUX, ... */ \
  1717. X(INT, NONE, sharrow_type) /* SHARROW_APPLICATION, SHARROW_BITMAP, ... */ \
  1718. X(BOOL, NONE, no_applic_c) /* totally disable app cursor keys */ \
  1719. X(BOOL, NONE, no_applic_k) /* totally disable app keypad */ \
  1720. X(BOOL, NONE, no_mouse_rep) /* totally disable mouse reporting */ \
  1721. X(BOOL, NONE, no_remote_resize) /* disable remote resizing */ \
  1722. X(BOOL, NONE, no_alt_screen) /* disable alternate screen */ \
  1723. X(BOOL, NONE, no_remote_wintitle) /* disable remote retitling */ \
  1724. X(BOOL, NONE, no_remote_clearscroll) /* disable ESC[3J */ \
  1725. X(BOOL, NONE, no_dbackspace) /* disable destructive backspace */ \
  1726. X(BOOL, NONE, no_remote_charset) /* disable remote charset config */ \
  1727. X(INT, NONE, remote_qtitle_action) /* remote win title query action
  1728. * (TITLE_NONE, TITLE_EMPTY, ...) */ \
  1729. X(BOOL, NONE, app_cursor) \
  1730. X(BOOL, NONE, app_keypad) \
  1731. X(BOOL, NONE, nethack_keypad) \
  1732. X(BOOL, NONE, telnet_keyboard) \
  1733. X(BOOL, NONE, telnet_newline) \
  1734. X(BOOL, NONE, alt_f4) /* is it special? */ \
  1735. X(BOOL, NONE, alt_space) /* is it special? */ \
  1736. X(BOOL, NONE, alt_only) /* is it special? */ \
  1737. X(INT, NONE, localecho) /* FORCE_ON, FORCE_OFF, AUTO */ \
  1738. X(INT, NONE, localedit) /* FORCE_ON, FORCE_OFF, AUTO */ \
  1739. X(BOOL, NONE, alwaysontop) \
  1740. X(BOOL, NONE, fullscreenonaltenter) \
  1741. X(BOOL, NONE, scroll_on_key) \
  1742. X(BOOL, NONE, scroll_on_disp) \
  1743. X(BOOL, NONE, erase_to_scrollback) \
  1744. X(BOOL, NONE, compose_key) \
  1745. X(BOOL, NONE, ctrlaltkeys) \
  1746. X(BOOL, NONE, osx_option_meta) \
  1747. X(BOOL, NONE, osx_command_meta) \
  1748. X(STR, NONE, wintitle) /* initial window title */ \
  1749. /* Terminal options */ \
  1750. X(INT, NONE, savelines) \
  1751. X(BOOL, NONE, dec_om) \
  1752. X(BOOL, NONE, wrap_mode) \
  1753. X(BOOL, NONE, lfhascr) \
  1754. X(INT, NONE, cursor_type) /* 0=block 1=underline 2=vertical */ \
  1755. X(BOOL, NONE, blink_cur) \
  1756. X(INT, NONE, beep) /* BELL_DISABLED, BELL_DEFAULT, ... */ \
  1757. X(INT, NONE, beep_ind) /* B_IND_DISABLED, B_IND_FLASH, ... */ \
  1758. X(BOOL, NONE, bellovl) /* bell overload protection active? */ \
  1759. X(INT, NONE, bellovl_n) /* number of bells to cause overload */ \
  1760. X(INT, NONE, bellovl_t) /* time interval for overload (seconds) */ \
  1761. X(INT, NONE, bellovl_s) /* period of silence to re-enable bell (s) */ \
  1762. X(FILENAME, NONE, bell_wavefile) \
  1763. X(BOOL, NONE, scrollbar) \
  1764. X(BOOL, NONE, scrollbar_in_fullscreen) \
  1765. X(INT, NONE, resize_action) /* RESIZE_TERM, RESIZE_DISABLED, ... */ \
  1766. X(BOOL, NONE, bce) \
  1767. X(BOOL, NONE, blinktext) \
  1768. X(BOOL, NONE, win_name_always) \
  1769. X(INT, NONE, width) \
  1770. X(INT, NONE, height) \
  1771. X(FONT, NONE, font) \
  1772. X(INT, NONE, font_quality) /* FQ_DEFAULT, FQ_ANTIALIASED, ... */ \
  1773. X(FILENAME, NONE, logfilename) \
  1774. X(INT, NONE, logtype) /* LGTYP_NONE, LGTYPE_ASCII, ... */ \
  1775. X(INT, NONE, logxfovr) /* LGXF_OVR, LGXF_APN, LGXF_ASK */ \
  1776. X(BOOL, NONE, logflush) \
  1777. X(BOOL, NONE, logheader) \
  1778. X(BOOL, NONE, logomitpass) \
  1779. X(BOOL, NONE, logomitdata) \
  1780. X(BOOL, NONE, hide_mouseptr) \
  1781. X(BOOL, NONE, sunken_edge) \
  1782. X(INT, NONE, window_border) /* in pixels */ \
  1783. X(STR, NONE, answerback) \
  1784. X(STR, NONE, printer) \
  1785. X(BOOL, NONE, no_arabicshaping) \
  1786. X(BOOL, NONE, no_bidi) \
  1787. /* Colour options */ \
  1788. X(BOOL, NONE, ansi_colour) \
  1789. X(BOOL, NONE, xterm_256_colour) \
  1790. X(BOOL, NONE, true_colour) \
  1791. X(BOOL, NONE, system_colour) \
  1792. X(BOOL, NONE, try_palette) \
  1793. X(INT, NONE, bold_style) /* 1=font 2=colour (3=both) */ \
  1794. X(INT, INT, colours) /* indexed by the CONF_COLOUR_* enum encoding */ \
  1795. /* Selection options */ \
  1796. X(INT, NONE, mouse_is_xterm) /* 0=compromise 1=xterm 2=Windows */ \
  1797. X(BOOL, NONE, rect_select) \
  1798. X(BOOL, NONE, paste_controls) \
  1799. X(BOOL, NONE, rawcnp) \
  1800. X(BOOL, NONE, utf8linedraw) \
  1801. X(BOOL, NONE, rtf_paste) \
  1802. X(BOOL, NONE, mouse_override) \
  1803. X(INT, INT, wordness) \
  1804. X(BOOL, NONE, mouseautocopy) \
  1805. X(INT, NONE, mousepaste) /* CLIPUI_IMPLICIT, CLIPUI_EXPLICIT, ... */ \
  1806. X(INT, NONE, ctrlshiftins) /* CLIPUI_IMPLICIT, CLIPUI_EXPLICIT, ... */ \
  1807. X(INT, NONE, ctrlshiftcv) /* CLIPUI_IMPLICIT, CLIPUI_EXPLICIT, ... */ \
  1808. X(STR, NONE, mousepaste_custom) \
  1809. X(STR, NONE, ctrlshiftins_custom) \
  1810. X(STR, NONE, ctrlshiftcv_custom) \
  1811. /* translations */ \
  1812. X(INT, NONE, vtmode) /* VT_XWINDOWS, VT_OEMANSI, ... */ \
  1813. X(STR, NONE, line_codepage) \
  1814. X(BOOL, NONE, cjk_ambig_wide) \
  1815. X(BOOL, NONE, utf8_override) \
  1816. X(BOOL, NONE, xlat_capslockcyr) \
  1817. /* X11 forwarding */ \
  1818. X(BOOL, NONE, x11_forward) \
  1819. X(STR, NONE, x11_display) \
  1820. X(INT, NONE, x11_auth) /* X11_NO_AUTH, X11_MIT, X11_XDM */ \
  1821. X(FILENAME, NONE, xauthfile) \
  1822. /* port forwarding */ \
  1823. X(BOOL, NONE, lport_acceptall) /* accept conns from hosts other than localhost */ \
  1824. X(BOOL, NONE, rport_acceptall) /* same for remote forwarded ports (SSH-2 only) */ \
  1825. /* \
  1826. * Subkeys for 'portfwd' can have the following forms: \
  1827. * \
  1828. * [LR]localport \
  1829. * [LR]localaddr:localport \
  1830. * \
  1831. * Dynamic forwardings are indicated by an 'L' key, and the \
  1832. * special value "D". For all other forwardings, the value \
  1833. * should be of the form 'host:port'. \
  1834. */ \
  1835. X(STR, STR, portfwd) \
  1836. /* SSH bug compatibility modes. All FORCE_ON/FORCE_OFF/AUTO */ \
  1837. X(INT, NONE, sshbug_ignore1) \
  1838. X(INT, NONE, sshbug_plainpw1) \
  1839. X(INT, NONE, sshbug_rsa1) \
  1840. X(INT, NONE, sshbug_hmac2) \
  1841. X(INT, NONE, sshbug_derivekey2) \
  1842. X(INT, NONE, sshbug_rsapad2) \
  1843. X(INT, NONE, sshbug_pksessid2) \
  1844. X(INT, NONE, sshbug_rekey2) \
  1845. X(INT, NONE, sshbug_maxpkt2) \
  1846. X(INT, NONE, sshbug_ignore2) \
  1847. X(INT, NONE, sshbug_oldgex2) \
  1848. X(INT, NONE, sshbug_winadj) \
  1849. X(INT, NONE, sshbug_chanreq) \
  1850. X(INT, NONE, sshbug_dropstart) \
  1851. X(INT, NONE, sshbug_filter_kexinit) \
  1852. X(INT, NONE, sshbug_rsa_sha2_cert_userauth) \
  1853. /* \
  1854. * ssh_simple means that we promise never to open any channel \
  1855. * other than the main one, which means it can safely use a very \
  1856. * large window in SSH-2. \
  1857. */ \
  1858. X(BOOL, NONE, ssh_simple) \
  1859. X(BOOL, NONE, ssh_connection_sharing) \
  1860. X(BOOL, NONE, ssh_connection_sharing_upstream) \
  1861. X(BOOL, NONE, ssh_connection_sharing_downstream) \
  1862. /*
  1863. * ssh_manual_hostkeys is conceptually a set rather than a
  1864. * dictionary: the string subkeys are the important thing, and the
  1865. * actual values to which those subkeys map are all "".
  1866. */ \
  1867. X(STR, STR, ssh_manual_hostkeys) \
  1868. /* Options for pterm. Should split out into platform-dependent part. */ \
  1869. X(BOOL, NONE, stamp_utmp) \
  1870. X(BOOL, NONE, login_shell) \
  1871. X(BOOL, NONE, scrollbar_on_left) \
  1872. X(BOOL, NONE, shadowbold) \
  1873. X(FONT, NONE, boldfont) \
  1874. X(FONT, NONE, widefont) \
  1875. X(FONT, NONE, wideboldfont) \
  1876. X(INT, NONE, shadowboldoffset) /* in pixels */ \
  1877. X(BOOL, NONE, crhaslf) \
  1878. X(STR, NONE, winclass) \
  1879. /* end of list */
  1880. /* Now define the actual enum of option keywords using that macro. */
  1881. #define CONF_ENUM_DEF(valtype, keytype, keyword) CONF_ ## keyword,
  1882. enum config_primary_key { CONFIG_OPTIONS(CONF_ENUM_DEF) N_CONFIG_OPTIONS };
  1883. #undef CONF_ENUM_DEF
  1884. /* Functions handling configuration structures. */
  1885. Conf *conf_new(void); /* create an empty configuration */
  1886. void conf_free(Conf *conf);
  1887. Conf *conf_copy(Conf *oldconf);
  1888. void conf_copy_into(Conf *dest, Conf *src);
  1889. /* Mandatory accessor functions: enforce by assertion that keys exist. */
  1890. bool conf_get_bool(Conf *conf, int key);
  1891. int conf_get_int(Conf *conf, int key);
  1892. int conf_get_int_int(Conf *conf, int key, int subkey);
  1893. char *conf_get_str(Conf *conf, int key); /* result still owned by conf */
  1894. char *conf_get_str_str(Conf *conf, int key, const char *subkey);
  1895. Filename *conf_get_filename(Conf *conf, int key);
  1896. FontSpec *conf_get_fontspec(Conf *conf, int key); /* still owned by conf */
  1897. /* Optional accessor function: return NULL if key does not exist. */
  1898. char *conf_get_str_str_opt(Conf *conf, int key, const char *subkey);
  1899. /* Accessor function to step through a string-subkeyed list.
  1900. * Returns the next subkey after the provided one, or the first if NULL.
  1901. * Returns NULL if there are none left.
  1902. * Both the return value and *subkeyout are still owned by conf. */
  1903. char *conf_get_str_strs(Conf *conf, int key, char *subkeyin, char **subkeyout);
  1904. /* Return the nth string subkey in a list. Owned by conf. NULL if beyond end */
  1905. char *conf_get_str_nthstrkey(Conf *conf, int key, int n);
  1906. /* Functions to set entries in configuration. Always copy their inputs. */
  1907. void conf_set_bool(Conf *conf, int key, bool value);
  1908. void conf_set_int(Conf *conf, int key, int value);
  1909. void conf_set_int_int(Conf *conf, int key, int subkey, int value);
  1910. void conf_set_str(Conf *conf, int key, const char *value);
  1911. void conf_set_str_str(Conf *conf, int key,
  1912. const char *subkey, const char *val);
  1913. void conf_del_str_str(Conf *conf, int key, const char *subkey);
  1914. void conf_set_filename(Conf *conf, int key, const Filename *val);
  1915. void conf_set_fontspec(Conf *conf, int key, const FontSpec *val);
  1916. /* Serialisation functions for Duplicate Session */
  1917. void conf_serialise(BinarySink *bs, Conf *conf);
  1918. bool conf_deserialise(Conf *conf, BinarySource *src);/*returns true on success*/
  1919. /*
  1920. * Functions to copy, free, serialise and deserialise FontSpecs.
  1921. * Provided per-platform, to go with the platform's idea of a
  1922. * FontSpec's contents.
  1923. */
  1924. FontSpec *fontspec_copy(const FontSpec *f);
  1925. void fontspec_free(FontSpec *f);
  1926. void fontspec_serialise(BinarySink *bs, FontSpec *f);
  1927. FontSpec *fontspec_deserialise(BinarySource *src);
  1928. /*
  1929. * Exports from each platform's noise.c.
  1930. */
  1931. typedef enum NoiseSourceId {
  1932. NOISE_SOURCE_TIME,
  1933. NOISE_SOURCE_IOID,
  1934. NOISE_SOURCE_IOLEN,
  1935. NOISE_SOURCE_KEY,
  1936. NOISE_SOURCE_MOUSEBUTTON,
  1937. NOISE_SOURCE_MOUSEPOS,
  1938. NOISE_SOURCE_MEMINFO,
  1939. NOISE_SOURCE_STAT,
  1940. NOISE_SOURCE_RUSAGE,
  1941. NOISE_SOURCE_FGWINDOW,
  1942. NOISE_SOURCE_CAPTURE,
  1943. NOISE_SOURCE_CLIPBOARD,
  1944. NOISE_SOURCE_QUEUE,
  1945. NOISE_SOURCE_CURSORPOS,
  1946. NOISE_SOURCE_THREADTIME,
  1947. NOISE_SOURCE_PROCTIME,
  1948. NOISE_SOURCE_PERFCOUNT,
  1949. NOISE_MAX_SOURCES
  1950. } NoiseSourceId;
  1951. void noise_get_heavy(void (*func) (void *, int));
  1952. void noise_get_light(void (*func) (void *, int));
  1953. void noise_regular(void);
  1954. void noise_ultralight(NoiseSourceId id, unsigned long data);
  1955. /*
  1956. * Exports from sshrand.c.
  1957. */
  1958. void random_save_seed(void);
  1959. void random_destroy_seed(void);
  1960. /*
  1961. * Exports from settings.c.
  1962. *
  1963. * load_settings() and do_defaults() return false if the provided
  1964. * session name didn't actually exist. But they still fill in the
  1965. * provided Conf with _something_.
  1966. */
  1967. const struct BackendVtable *backend_vt_from_name(const char *name);
  1968. const struct BackendVtable *backend_vt_from_proto(int proto);
  1969. char *get_remote_username(Conf *conf); /* dynamically allocated */
  1970. char *save_settings(const char *section, Conf *conf);
  1971. void save_open_settings(settings_w *sesskey, Conf *conf);
  1972. bool load_settings(const char *section, Conf *conf);
  1973. void load_open_settings(settings_r *sesskey, Conf *conf);
  1974. void get_sesslist(struct sesslist *, bool allocate);
  1975. bool do_defaults(const char *, Conf *);
  1976. void registry_cleanup(void);
  1977. void settings_set_default_protocol(int);
  1978. void settings_set_default_port(int);
  1979. /*
  1980. * Functions used by settings.c to provide platform-specific
  1981. * default settings.
  1982. *
  1983. * (The integer one is expected to return `def' if it has no clear
  1984. * opinion of its own. This is because there's no integer value
  1985. * which I can reliably set aside to indicate `nil'. The string
  1986. * function is perfectly all right returning NULL, of course. The
  1987. * Filename and FontSpec functions are _not allowed_ to fail to
  1988. * return, since these defaults _must_ be per-platform.)
  1989. *
  1990. * The 'Filename *' returned by platform_default_filename, and the
  1991. * 'FontSpec *' returned by platform_default_fontspec, have ownership
  1992. * transferred to the caller, and must be freed.
  1993. */
  1994. char *platform_default_s(const char *name);
  1995. bool platform_default_b(const char *name, bool def);
  1996. int platform_default_i(const char *name, int def);
  1997. Filename *platform_default_filename(const char *name);
  1998. FontSpec *platform_default_fontspec(const char *name);
  1999. /*
  2000. * Exports from terminal.c.
  2001. */
  2002. Terminal *term_init(Conf *, struct unicode_data *, TermWin *);
  2003. void term_free(Terminal *);
  2004. void term_size(Terminal *, int, int, int);
  2005. void term_resize_request_completed(Terminal *);
  2006. void term_paint(Terminal *, int, int, int, int, bool);
  2007. void term_scroll(Terminal *, int, int);
  2008. void term_scroll_to_selection(Terminal *, int);
  2009. void term_pwron(Terminal *, bool);
  2010. void term_clrsb(Terminal *);
  2011. void term_mouse(Terminal *, Mouse_Button, Mouse_Button, Mouse_Action,
  2012. int, int, bool, bool, bool);
  2013. void term_cancel_selection_drag(Terminal *);
  2014. void term_key(Terminal *, Key_Sym, wchar_t *, size_t, unsigned int,
  2015. unsigned int);
  2016. void term_lost_clipboard_ownership(Terminal *, int clipboard);
  2017. void term_update(Terminal *);
  2018. void term_invalidate(Terminal *);
  2019. void term_blink(Terminal *, bool set_cursor);
  2020. void term_do_paste(Terminal *, const wchar_t *, int);
  2021. void term_nopaste(Terminal *);
  2022. void term_copyall(Terminal *, const int *, int);
  2023. void term_pre_reconfig(Terminal *, Conf *);
  2024. void term_reconfig(Terminal *, Conf *);
  2025. void term_request_copy(Terminal *, const int *clipboards, int n_clipboards);
  2026. void term_request_paste(Terminal *, int clipboard);
  2027. void term_seen_key_event(Terminal *);
  2028. size_t term_data(Terminal *, const void *data, size_t len);
  2029. void term_provide_backend(Terminal *term, Backend *backend);
  2030. void term_provide_logctx(Terminal *term, LogContext *logctx);
  2031. void term_set_focus(Terminal *term, bool has_focus);
  2032. char *term_get_ttymode(Terminal *term, const char *mode);
  2033. SeatPromptResult term_get_userpass_input(Terminal *term, prompts_t *p);
  2034. void term_set_trust_status(Terminal *term, bool trusted);
  2035. void term_keyinput(Terminal *, int codepage, const void *buf, int len);
  2036. void term_keyinputw(Terminal *, const wchar_t *widebuf, int len);
  2037. void term_get_cursor_position(Terminal *term, int *x, int *y);
  2038. void term_setup_window_titles(Terminal *term, const char *title_hostname);
  2039. void term_notify_minimised(Terminal *term, bool minimised);
  2040. void term_notify_palette_changed(Terminal *term);
  2041. void term_notify_window_pos(Terminal *term, int x, int y);
  2042. void term_notify_window_size_pixels(Terminal *term, int x, int y);
  2043. void term_palette_override(Terminal *term, unsigned osc4_index, rgb rgb);
  2044. typedef enum SmallKeypadKey {
  2045. SKK_HOME, SKK_END, SKK_INSERT, SKK_DELETE, SKK_PGUP, SKK_PGDN,
  2046. } SmallKeypadKey;
  2047. int format_arrow_key(char *buf, Terminal *term, int xkey,
  2048. bool shift, bool ctrl, bool alt, bool *consumed_alt);
  2049. int format_function_key(char *buf, Terminal *term, int key_number,
  2050. bool shift, bool ctrl, bool alt, bool *consumed_alt);
  2051. int format_small_keypad_key(char *buf, Terminal *term, SmallKeypadKey key,
  2052. bool shift, bool ctrl, bool alt,
  2053. bool *consumed_alt);
  2054. int format_numeric_keypad_key(char *buf, Terminal *term, char key,
  2055. bool shift, bool ctrl);
  2056. /*
  2057. * Exports from logging.c.
  2058. */
  2059. struct LogPolicyVtable {
  2060. /*
  2061. * Pass Event Log entries on from LogContext to the front end,
  2062. * which might write them to standard error or save them for a GUI
  2063. * list box or other things.
  2064. */
  2065. void (*eventlog)(LogPolicy *lp, const char *event);
  2066. /*
  2067. * Ask what to do about the specified output log file already
  2068. * existing. Can return four values:
  2069. *
  2070. * - 2 means overwrite the log file
  2071. * - 1 means append to the log file
  2072. * - 0 means cancel logging for this session
  2073. * - -1 means please wait, and callback() will be called with one
  2074. * of those options.
  2075. */
  2076. int (*askappend)(LogPolicy *lp, Filename *filename,
  2077. void (*callback)(void *ctx, int result), void *ctx);
  2078. /*
  2079. * Emergency logging when the log file itself can't be opened,
  2080. * which typically means we want to shout about it more loudly
  2081. * than a mere Event Log entry.
  2082. *
  2083. * One reasonable option is to send it to the same place that
  2084. * stderr output from the main session goes (so, either a console
  2085. * tool's actual stderr, or a terminal window). In many cases this
  2086. * is unlikely to cause this error message to turn up
  2087. * embarrassingly in a log file of real server output, because the
  2088. * whole point is that we haven't managed to open any such log
  2089. * file :-)
  2090. */
  2091. void (*logging_error)(LogPolicy *lp, const char *event);
  2092. /*
  2093. * Ask whether extra verbose log messages are required.
  2094. */
  2095. bool (*verbose)(LogPolicy *lp);
  2096. };
  2097. struct LogPolicy {
  2098. const LogPolicyVtable *vt;
  2099. };
  2100. static inline void lp_eventlog(LogPolicy *lp, const char *event)
  2101. { lp->vt->eventlog(lp, event); }
  2102. static inline int lp_askappend(
  2103. LogPolicy *lp, Filename *filename,
  2104. void (*callback)(void *ctx, int result), void *ctx)
  2105. { return lp->vt->askappend(lp, filename, callback, ctx); }
  2106. static inline void lp_logging_error(LogPolicy *lp, const char *event)
  2107. { lp->vt->logging_error(lp, event); }
  2108. static inline bool lp_verbose(LogPolicy *lp)
  2109. { return lp->vt->verbose(lp); }
  2110. /* Defined in clicons.c, used in several console command-line tools */
  2111. extern LogPolicy console_cli_logpolicy[];
  2112. int console_askappend(LogPolicy *lp, Filename *filename,
  2113. void (*callback)(void *ctx, int result), void *ctx);
  2114. void console_logging_error(LogPolicy *lp, const char *string);
  2115. void console_eventlog(LogPolicy *lp, const char *string);
  2116. bool null_lp_verbose_yes(LogPolicy *lp);
  2117. bool null_lp_verbose_no(LogPolicy *lp);
  2118. bool cmdline_lp_verbose(LogPolicy *lp);
  2119. LogContext *log_init(LogPolicy *lp, Conf *conf);
  2120. void log_free(LogContext *logctx);
  2121. void log_reconfig(LogContext *logctx, Conf *conf);
  2122. void logfopen(LogContext *logctx);
  2123. void logfclose(LogContext *logctx);
  2124. void logtraffic(LogContext *logctx, unsigned char c, int logmode);
  2125. void logflush(LogContext *logctx);
  2126. LogPolicy *log_get_policy(LogContext *logctx);
  2127. void logevent(LogContext *logctx, const char *event);
  2128. void logeventf(LogContext *logctx, const char *fmt, ...) PRINTF_LIKE(2, 3);
  2129. void logeventvf(LogContext *logctx, const char *fmt, va_list ap);
  2130. /*
  2131. * Pass a dynamically allocated string to logevent and immediately
  2132. * free it. Intended for use by wrapper macros which pass the return
  2133. * value of dupprintf straight to this.
  2134. */
  2135. void logevent_and_free(LogContext *logctx, char *event);
  2136. enum { PKT_INCOMING, PKT_OUTGOING };
  2137. enum { PKTLOG_EMIT, PKTLOG_BLANK, PKTLOG_OMIT };
  2138. struct logblank_t {
  2139. int offset;
  2140. int len;
  2141. int type;
  2142. };
  2143. void log_packet(LogContext *logctx, int direction, int type,
  2144. const char *texttype, const void *data, size_t len,
  2145. int n_blanks, const struct logblank_t *blanks,
  2146. const unsigned long *sequence,
  2147. unsigned downstream_id, const char *additional_log_text);
  2148. /*
  2149. * Exports from testback.c
  2150. */
  2151. extern const struct BackendVtable null_backend;
  2152. extern const struct BackendVtable loop_backend;
  2153. /*
  2154. * Exports from raw.c.
  2155. */
  2156. extern const struct BackendVtable raw_backend;
  2157. /*
  2158. * Exports from rlogin.c.
  2159. */
  2160. extern const struct BackendVtable rlogin_backend;
  2161. /*
  2162. * Exports from telnet.c.
  2163. */
  2164. extern const struct BackendVtable telnet_backend;
  2165. /*
  2166. * Exports from ssh/ssh.c.
  2167. */
  2168. extern const struct BackendVtable ssh_backend;
  2169. extern const struct BackendVtable sshconn_backend;
  2170. /*
  2171. * Exports from supdup.c.
  2172. */
  2173. extern const struct BackendVtable supdup_backend;
  2174. /*
  2175. * Exports from ldisc.c.
  2176. */
  2177. Ldisc *ldisc_create(Conf *, Terminal *, Backend *, Seat *);
  2178. void ldisc_configure(Ldisc *, Conf *);
  2179. void ldisc_free(Ldisc *);
  2180. void ldisc_send(Ldisc *, const void *buf, int len, bool interactive);
  2181. void ldisc_echoedit_update(Ldisc *);
  2182. typedef struct LdiscInputToken {
  2183. /*
  2184. * Structure that encodes any single item of data that Ldisc can
  2185. * buffer: either a single character of raw data, or a session
  2186. * special.
  2187. */
  2188. bool is_special;
  2189. union {
  2190. struct {
  2191. /* if is_special == false */
  2192. char chr;
  2193. };
  2194. struct {
  2195. /* if is_special == true */
  2196. SessionSpecialCode code;
  2197. int arg;
  2198. };
  2199. };
  2200. } LdiscInputToken;
  2201. bool ldisc_has_input_buffered(Ldisc *);
  2202. LdiscInputToken ldisc_get_input_token(Ldisc *); /* asserts there is input */
  2203. void ldisc_enable_prompt_callback(Ldisc *, prompts_t *);
  2204. void ldisc_check_sendok(Ldisc *);
  2205. /*
  2206. * Exports from sshrand.c.
  2207. */
  2208. void random_add_noise(NoiseSourceId source, const void *noise, int length);
  2209. void random_read(void *buf, size_t size);
  2210. void random_get_savedata(void **data, int *len);
  2211. extern int random_active;
  2212. /* The random number subsystem is activated if at least one other entity
  2213. * within the program expresses an interest in it. So each SSH session
  2214. * calls random_ref on startup and random_unref on shutdown. */
  2215. void random_ref(void);
  2216. void random_unref(void);
  2217. /* random_clear is equivalent to calling random_unref as many times as
  2218. * necessary to shut down the global PRNG instance completely. It's
  2219. * not needed in normal applications, but the command-line PuTTYgen
  2220. * test finds it useful to clean up after each invocation of the
  2221. * logical main() no matter whether it needed random numbers or
  2222. * not. */
  2223. void random_clear(void);
  2224. /* random_setup_custom sets up the process-global random number
  2225. * generator specially, with a hash function of your choice. */
  2226. void random_setup_custom(const ssh_hashalg *hash);
  2227. /* random_setup_special() is a macro wrapper on that, which makes an
  2228. * extra-big one based on the largest hash function we have. It's
  2229. * defined this way to avoid what would otherwise be an unnecessary
  2230. * module dependency from sshrand.c to a hash function implementation. */
  2231. #define random_setup_special() random_setup_custom(&ssh_shake256_114bytes)
  2232. /* Manually drop a random seed into the random number generator, e.g.
  2233. * just before generating a key. */
  2234. void random_reseed(ptrlen seed);
  2235. /* Limit on how much entropy is worth putting into the generator (bits). */
  2236. size_t random_seed_bits(void);
  2237. /*
  2238. * Exports from pinger.c.
  2239. */
  2240. typedef struct Pinger Pinger;
  2241. Pinger *pinger_new(Conf *conf, Backend *backend);
  2242. void pinger_reconfig(Pinger *, Conf *oldconf, Conf *newconf);
  2243. void pinger_free(Pinger *);
  2244. /*
  2245. * Exports from modules in utils.
  2246. */
  2247. #include "misc.h"
  2248. bool conf_launchable(Conf *conf);
  2249. char const *conf_dest(Conf *conf);
  2250. /*
  2251. * Exports from sessprep.c.
  2252. */
  2253. void prepare_session(Conf *conf);
  2254. /*
  2255. * Exports from version.c and cmake_commit.c.
  2256. */
  2257. extern const char ver[];
  2258. extern const char commitid[];
  2259. /*
  2260. * Exports from unicode.c in platform subdirs.
  2261. */
  2262. #ifndef CP_UTF8
  2263. #define CP_UTF8 65001
  2264. #endif
  2265. /* void init_ucs(void); -- this is now in platform-specific headers */
  2266. bool is_dbcs_leadbyte(int codepage, char byte);
  2267. int mb_to_wc(int codepage, int flags, const char *mbstr, int mblen,
  2268. wchar_t *wcstr, int wclen);
  2269. int wc_to_mb(int codepage, int flags, const wchar_t *wcstr, int wclen,
  2270. char *mbstr, int mblen, const char *defchr);
  2271. wchar_t xlat_uskbd2cyrllic(int ch);
  2272. int check_compose(int first, int second);
  2273. int decode_codepage(const char *cp_name);
  2274. const char *cp_enumerate (int index);
  2275. const char *cp_name(int codepage);
  2276. void get_unitab(int codepage, wchar_t *unitab, int ftype);
  2277. /*
  2278. * Exports from wcwidth.c
  2279. */
  2280. int mk_wcwidth(unsigned int ucs);
  2281. int mk_wcswidth(const unsigned int *pwcs, size_t n);
  2282. int mk_wcwidth_cjk(unsigned int ucs);
  2283. int mk_wcswidth_cjk(const unsigned int *pwcs, size_t n);
  2284. /*
  2285. * Exports from agent-client.c in platform subdirs.
  2286. *
  2287. * agent_query returns NULL for here's-a-response, and non-NULL for
  2288. * query-in- progress. In the latter case there will be a call to
  2289. * `callback' at some future point, passing callback_ctx as the first
  2290. * parameter and the actual reply data as the second and third.
  2291. *
  2292. * The response may be a NULL pointer (in either of the synchronous
  2293. * or asynchronous cases), which indicates failure to receive a
  2294. * response.
  2295. *
  2296. * When the return from agent_query is not NULL, it identifies the
  2297. * in-progress query in case it needs to be cancelled. If
  2298. * agent_cancel_query is called, then the pending query is destroyed
  2299. * and the callback will not be called. (E.g. if you're going to throw
  2300. * away the thing you were using as callback_ctx.)
  2301. *
  2302. * Passing a null pointer as callback forces agent_query to behave
  2303. * synchronously, i.e. it will block if necessary, and guarantee to
  2304. * return NULL. The wrapper function agent_query_synchronous()
  2305. * (defined in its own module aqsync.c) makes this easier.
  2306. */
  2307. typedef struct agent_pending_query agent_pending_query;
  2308. agent_pending_query *agent_query(
  2309. strbuf *in, void **out, int *outlen,
  2310. void (*callback)(void *, void *, int), void *callback_ctx);
  2311. void agent_cancel_query(agent_pending_query *);
  2312. void agent_query_synchronous(strbuf *in, void **out, int *outlen);
  2313. bool agent_exists(void);
  2314. /* For stream-oriented agent connections, if available. */
  2315. Socket *agent_connect(Plug *plug);
  2316. /*
  2317. * Exports from wildcard.c
  2318. */
  2319. const char *wc_error(int value);
  2320. int wc_match_pl(const char *wildcard, ptrlen target);
  2321. int wc_match(const char *wildcard, const char *target);
  2322. bool wc_unescape(char *output, const char *wildcard);
  2323. /*
  2324. * Exports from frontend (dialog.c etc)
  2325. */
  2326. void pgp_fingerprints(void);
  2327. /*
  2328. * have_ssh_host_key() just returns true if a key of that type is
  2329. * already cached and false otherwise.
  2330. */
  2331. bool have_ssh_host_key(const char *host, int port, const char *keytype);
  2332. /*
  2333. * Exports from console frontends (console.c in platform subdirs)
  2334. * that aren't equivalents to things in windlg.c et al.
  2335. */
  2336. extern bool console_batch_mode, console_antispoof_prompt;
  2337. SeatPromptResult console_get_userpass_input(prompts_t *p);
  2338. bool is_interactive(void);
  2339. void console_print_error_msg(const char *prefix, const char *msg);
  2340. void console_print_error_msg_fmt_v(
  2341. const char *prefix, const char *fmt, va_list ap);
  2342. void console_print_error_msg_fmt(const char *prefix, const char *fmt, ...)
  2343. PRINTF_LIKE(2, 3);
  2344. /*
  2345. * Exports from printing.c in platform subdirs.
  2346. */
  2347. typedef struct printer_enum_tag printer_enum;
  2348. typedef struct printer_job_tag printer_job;
  2349. printer_enum *printer_start_enum(int *nprinters);
  2350. char *printer_get_name(printer_enum *, int);
  2351. void printer_finish_enum(printer_enum *);
  2352. printer_job *printer_start_job(char *printer);
  2353. void printer_job_data(printer_job *, const void *, size_t);
  2354. void printer_finish_job(printer_job *);
  2355. /*
  2356. * Exports from cmdline.c (and also cmdline_error(), which is
  2357. * defined differently in various places and required _by_
  2358. * cmdline.c).
  2359. *
  2360. * Note that cmdline_process_param takes a const option string, but a
  2361. * writable argument string. That's not a mistake - that's so it can
  2362. * zero out password arguments in the hope of not having them show up
  2363. * avoidably in Unix 'ps'.
  2364. */
  2365. struct cmdline_get_passwd_input_state { bool tried; };
  2366. #define CMDLINE_GET_PASSWD_INPUT_STATE_INIT { .tried = false }
  2367. extern const cmdline_get_passwd_input_state cmdline_get_passwd_input_state_new;
  2368. int cmdline_process_param(const char *, char *, int, Conf *);
  2369. void cmdline_run_saved(Conf *);
  2370. void cmdline_cleanup(void);
  2371. SeatPromptResult cmdline_get_passwd_input(
  2372. prompts_t *p, cmdline_get_passwd_input_state *state, bool restartable);
  2373. bool cmdline_host_ok(Conf *);
  2374. bool cmdline_verbose(void);
  2375. bool cmdline_loaded_session(void);
  2376. /*
  2377. * Here we have a flags word provided by each tool, which describes
  2378. * the capabilities of that tool that cmdline.c needs to know about.
  2379. * It will refuse certain command-line options if a particular tool
  2380. * inherently can't do anything sensible. For example, the file
  2381. * transfer tools (psftp, pscp) can't do a great deal with protocol
  2382. * selections (ever tried running scp over telnet?) or with port
  2383. * forwarding (even if it wasn't a hideously bad idea, they don't have
  2384. * the select/poll infrastructure to make them work).
  2385. */
  2386. extern const unsigned cmdline_tooltype;
  2387. /* Bit flags for the above */
  2388. #define TOOLTYPE_LIST(X) \
  2389. X(TOOLTYPE_FILETRANSFER) \
  2390. X(TOOLTYPE_NONNETWORK) \
  2391. X(TOOLTYPE_HOST_ARG) \
  2392. X(TOOLTYPE_HOST_ARG_CAN_BE_SESSION) \
  2393. X(TOOLTYPE_HOST_ARG_PROTOCOL_PREFIX) \
  2394. X(TOOLTYPE_HOST_ARG_FROM_LAUNCHABLE_LOAD) \
  2395. X(TOOLTYPE_PORT_ARG) \
  2396. X(TOOLTYPE_NO_VERBOSE_OPTION) \
  2397. /* end of list */
  2398. #define BITFLAG_INDEX(val) val ## _bitflag_index,
  2399. enum { TOOLTYPE_LIST(BITFLAG_INDEX) };
  2400. #define BITFLAG_DEF(val) val = 1U << (val ## _bitflag_index),
  2401. enum { TOOLTYPE_LIST(BITFLAG_DEF) };
  2402. void cmdline_error(const char *, ...) PRINTF_LIKE(1, 2);
  2403. /*
  2404. * Exports from config.c.
  2405. */
  2406. struct controlbox;
  2407. void conf_radiobutton_handler(dlgcontrol *ctrl, dlgparam *dlg,
  2408. void *data, int event);
  2409. #define CHECKBOX_INVERT (1<<30)
  2410. void conf_checkbox_handler(dlgcontrol *ctrl, dlgparam *dlg,
  2411. void *data, int event);
  2412. void conf_editbox_handler(dlgcontrol *ctrl, dlgparam *dlg,
  2413. void *data, int event);
  2414. void conf_filesel_handler(dlgcontrol *ctrl, dlgparam *dlg,
  2415. void *data, int event);
  2416. void conf_fontsel_handler(dlgcontrol *ctrl, dlgparam *dlg,
  2417. void *data, int event);
  2418. struct conf_editbox_handler_type {
  2419. /* Structure passed as context2 to conf_editbox_handler */
  2420. enum { EDIT_STR, EDIT_INT, EDIT_FIXEDPOINT } type;
  2421. union {
  2422. /*
  2423. * EDIT_STR means the edit box is connected to a string
  2424. * field in Conf. No further parameters needed.
  2425. */
  2426. /*
  2427. * EDIT_INT means the edit box is connected to an int field in
  2428. * Conf, and the input string is interpreted as decimal. No
  2429. * further parameters needed. (But we could add one here later
  2430. * if for some reason we wanted int fields in hex.)
  2431. */
  2432. /*
  2433. * EDIT_FIXEDPOINT means the edit box is connected to an int
  2434. * field in Conf, but the input string is interpreted as
  2435. * _floating point_, and converted to/from the output int by
  2436. * means of a fixed denominator. That is,
  2437. *
  2438. * (floating value in edit box) * denominator = value in Conf
  2439. */
  2440. struct {
  2441. double denominator;
  2442. };
  2443. };
  2444. };
  2445. extern const struct conf_editbox_handler_type conf_editbox_str;
  2446. extern const struct conf_editbox_handler_type conf_editbox_int;
  2447. #define ED_STR CP(&conf_editbox_str)
  2448. #define ED_INT CP(&conf_editbox_int)
  2449. void setup_config_box(struct controlbox *b, bool midsession,
  2450. int protocol, int protcfginfo);
  2451. void setup_ca_config_box(struct controlbox *b);
  2452. /* Platforms provide this to be called from config.c */
  2453. void show_ca_config_box(dlgparam *dlg);
  2454. extern const bool has_ca_config_box; /* false if, e.g., we're PuTTYtel */
  2455. /* Visible outside config.c so that platforms can use it to recognise
  2456. * the proxy type control */
  2457. void proxy_type_handler(dlgcontrol *ctrl, dlgparam *dlg,
  2458. void *data, int event);
  2459. /* And then they'll set this flag in its generic.context.i */
  2460. #define PROXY_UI_FLAG_LOCAL 1 /* has a local proxy */
  2461. /*
  2462. * Exports from bidi.c.
  2463. */
  2464. #define BIDI_CHAR_INDEX_NONE ((unsigned short)-1)
  2465. typedef struct bidi_char {
  2466. unsigned int origwc, wc;
  2467. unsigned short index, nchars;
  2468. } bidi_char;
  2469. BidiContext *bidi_new_context(void);
  2470. void bidi_free_context(BidiContext *ctx);
  2471. void do_bidi(BidiContext *ctx, bidi_char *line, size_t count);
  2472. int do_shape(bidi_char *line, bidi_char *to, int count);
  2473. bool is_rtl(int c);
  2474. /*
  2475. * X11 auth mechanisms we know about.
  2476. */
  2477. enum {
  2478. X11_NO_AUTH,
  2479. X11_MIT, /* MIT-MAGIC-COOKIE-1 */
  2480. X11_XDM, /* XDM-AUTHORIZATION-1 */
  2481. X11_NAUTHS
  2482. };
  2483. extern const char *const x11_authnames[X11_NAUTHS];
  2484. /*
  2485. * An enum for the copy-paste UI action configuration.
  2486. */
  2487. enum {
  2488. CLIPUI_NONE, /* UI action has no copy/paste effect */
  2489. CLIPUI_IMPLICIT, /* use the default clipboard implicit in mouse actions */
  2490. CLIPUI_EXPLICIT, /* use the default clipboard for explicit Copy/Paste */
  2491. CLIPUI_CUSTOM, /* use a named clipboard (on systems that support it) */
  2492. };
  2493. /*
  2494. * Miscellaneous exports from the platform-specific code.
  2495. *
  2496. * filename_serialise and filename_deserialise have the same semantics
  2497. * as fontspec_serialise and fontspec_deserialise above.
  2498. */
  2499. Filename *filename_from_str(const char *string);
  2500. const char *filename_to_str(const Filename *fn);
  2501. bool filename_equal(const Filename *f1, const Filename *f2);
  2502. bool filename_is_null(const Filename *fn);
  2503. Filename *filename_copy(const Filename *fn);
  2504. void filename_free(Filename *fn);
  2505. void filename_serialise(BinarySink *bs, const Filename *f);
  2506. Filename *filename_deserialise(BinarySource *src);
  2507. char *get_username(void); /* return value needs freeing */
  2508. char *get_random_data(int bytes, const char *device); /* used in cmdgen.c */
  2509. char filename_char_sanitise(char c); /* rewrite special pathname chars */
  2510. bool open_for_write_would_lose_data(const Filename *fn);
  2511. /*
  2512. * Exports and imports from timing.c.
  2513. *
  2514. * schedule_timer() asks the front end to schedule a callback to a
  2515. * timer function in a given number of ticks. The returned value is
  2516. * the time (in ticks since an arbitrary offset) at which the
  2517. * callback can be expected. This value will also be passed as the
  2518. * `now' parameter to the callback function. Hence, you can (for
  2519. * example) schedule an event at a particular time by calling
  2520. * schedule_timer() and storing the return value in your context
  2521. * structure as the time when that event is due. The first time a
  2522. * callback function gives you that value or more as `now', you do
  2523. * the thing.
  2524. *
  2525. * expire_timer_context() drops all current timers associated with
  2526. * a given value of ctx (for when you're about to free ctx).
  2527. *
  2528. * run_timers() is called from the front end when it has reason to
  2529. * think some timers have reached their moment, or when it simply
  2530. * needs to know how long to wait next. We pass it the time we
  2531. * think it is. It returns true and places the time when the next
  2532. * timer needs to go off in `next', or alternatively it returns
  2533. * false if there are no timers at all pending.
  2534. *
  2535. * timer_change_notify() must be supplied by the front end; it
  2536. * notifies the front end that a new timer has been added to the
  2537. * list which is sooner than any existing ones. It provides the
  2538. * time when that timer needs to go off.
  2539. *
  2540. * *** FRONT END IMPLEMENTORS NOTE:
  2541. *
  2542. * There's an important subtlety in the front-end implementation of
  2543. * the timer interface. When a front end is given a `next' value,
  2544. * either returned from run_timers() or via timer_change_notify(),
  2545. * it should ensure that it really passes _that value_ as the `now'
  2546. * parameter to its next run_timers call. It should _not_ simply
  2547. * call GETTICKCOUNT() to get the `now' parameter when invoking
  2548. * run_timers().
  2549. *
  2550. * The reason for this is that an OS's system clock might not agree
  2551. * exactly with the timing mechanisms it supplies to wait for a
  2552. * given interval. I'll illustrate this by the simple example of
  2553. * Unix Plink, which uses timeouts to poll() in a way which for
  2554. * these purposes can simply be considered to be a wait() function.
  2555. * Suppose, for the sake of argument, that this wait() function
  2556. * tends to return early by 1%. Then a possible sequence of actions
  2557. * is:
  2558. *
  2559. * - run_timers() tells the front end that the next timer firing
  2560. * is 10000ms from now.
  2561. * - Front end calls wait(10000ms), but according to
  2562. * GETTICKCOUNT() it has only waited for 9900ms.
  2563. * - Front end calls run_timers() again, passing time T-100ms as
  2564. * `now'.
  2565. * - run_timers() does nothing, and says the next timer firing is
  2566. * still 100ms from now.
  2567. * - Front end calls wait(100ms), which only waits for 99ms.
  2568. * - Front end calls run_timers() yet again, passing time T-1ms.
  2569. * - run_timers() says there's still 1ms to wait.
  2570. * - Front end calls wait(1ms).
  2571. *
  2572. * If you're _lucky_ at this point, wait(1ms) will actually wait
  2573. * for 1ms and you'll only have woken the program up three times.
  2574. * If you're unlucky, wait(1ms) might do nothing at all due to
  2575. * being below some minimum threshold, and you might find your
  2576. * program spends the whole of the last millisecond tight-looping
  2577. * between wait() and run_timers().
  2578. *
  2579. * Instead, what you should do is to _save_ the precise `next'
  2580. * value provided by run_timers() or via timer_change_notify(), and
  2581. * use that precise value as the input to the next run_timers()
  2582. * call. So:
  2583. *
  2584. * - run_timers() tells the front end that the next timer firing
  2585. * is at time T, 10000ms from now.
  2586. * - Front end calls wait(10000ms).
  2587. * - Front end then immediately calls run_timers() and passes it
  2588. * time T, without stopping to check GETTICKCOUNT() at all.
  2589. *
  2590. * This guarantees that the program wakes up only as many times as
  2591. * there are actual timer actions to be taken, and that the timing
  2592. * mechanism will never send it into a tight loop.
  2593. *
  2594. * (It does also mean that the timer action in the above example
  2595. * will occur 100ms early, but this is not generally critical. And
  2596. * the hypothetical 1% error in wait() will be partially corrected
  2597. * for anyway when, _after_ run_timers() returns, you call
  2598. * GETTICKCOUNT() and compare the result with the returned `next'
  2599. * value to find out how long you have to make your next wait().)
  2600. */
  2601. typedef void (*timer_fn_t)(void *ctx, unsigned long now);
  2602. unsigned long schedule_timer(int ticks, timer_fn_t fn, void *ctx);
  2603. void expire_timer_context(void *ctx);
  2604. bool run_timers(unsigned long now, unsigned long *next);
  2605. void timer_change_notify(unsigned long next);
  2606. unsigned long timing_last_clock(void);
  2607. /*
  2608. * Exports from callback.c.
  2609. *
  2610. * This provides a method of queuing function calls to be run at the
  2611. * earliest convenience from the top-level event loop. Use it if
  2612. * you're deep in a nested chain of calls and want to trigger an
  2613. * action which will probably lead to your function being re-entered
  2614. * recursively if you just call the initiating function the normal
  2615. * way.
  2616. *
  2617. * Most front ends run the queued callbacks by simply calling
  2618. * run_toplevel_callbacks() after handling each event in their
  2619. * top-level event loop. However, if a front end doesn't have control
  2620. * over its own event loop (e.g. because it's using GTK) then it can
  2621. * instead request notifications when a callback is available, so that
  2622. * it knows to ask its delegate event loop to do the same thing. Also,
  2623. * if a front end needs to know whether a callback is pending without
  2624. * actually running it (e.g. so as to put a zero timeout on a poll()
  2625. * call) then it can call toplevel_callback_pending(), which will
  2626. * return true if at least one callback is in the queue.
  2627. *
  2628. * run_toplevel_callbacks() returns true if it ran any actual code.
  2629. * This can be used as a means of speculatively terminating a poll
  2630. * loop, as in PSFTP, for example - if a callback has run then perhaps
  2631. * it might have done whatever the loop's caller was waiting for.
  2632. */
  2633. void queue_toplevel_callback(toplevel_callback_fn_t fn, void *ctx);
  2634. bool run_toplevel_callbacks(void);
  2635. bool toplevel_callback_pending(void);
  2636. void delete_callbacks_for_context(void *ctx);
  2637. /*
  2638. * Another facility in callback.c deals with 'idempotent' callbacks,
  2639. * defined as those which never need to be scheduled again if they are
  2640. * already scheduled and have not yet run. (An example would be one
  2641. * which, when called, empties a queue of data completely: when data
  2642. * is added to the queue, you must ensure a run of the queue-consuming
  2643. * function has been scheduled, but if one is already pending, you
  2644. * don't need to schedule a second one.)
  2645. */
  2646. struct IdempotentCallback {
  2647. toplevel_callback_fn_t fn;
  2648. void *ctx;
  2649. bool queued;
  2650. };
  2651. void queue_idempotent_callback(struct IdempotentCallback *ic);
  2652. typedef void (*toplevel_callback_notify_fn_t)(void *ctx);
  2653. void request_callback_notifications(toplevel_callback_notify_fn_t notify,
  2654. void *ctx);
  2655. /*
  2656. * Facility provided by the platform to spawn a parallel subprocess
  2657. * and present its stdio via a Socket.
  2658. *
  2659. * 'prefix' indicates the prefix that should appear on messages passed
  2660. * to plug_log to provide stderr output from the process.
  2661. */
  2662. Socket *platform_start_subprocess(const char *cmd, Plug *plug,
  2663. const char *prefix);
  2664. /*
  2665. * Define no-op macros for the jump list functions, on platforms that
  2666. * don't support them. (This is a bit of a hack, and it'd be nicer to
  2667. * localise even the calls to those functions into the Windows front
  2668. * end, but it'll do for the moment.)
  2669. */
  2670. #ifndef JUMPLIST_SUPPORTED
  2671. #define add_session_to_jumplist(x) ((void)0)
  2672. #define remove_session_from_jumplist(x) ((void)0)
  2673. #endif
  2674. /* SURROGATE PAIR */
  2675. #ifndef HIGH_SURROGATE_START /* in some toolchains <winnls.h> defines these */
  2676. #define HIGH_SURROGATE_START 0xd800
  2677. #define HIGH_SURROGATE_END 0xdbff
  2678. #define LOW_SURROGATE_START 0xdc00
  2679. #define LOW_SURROGATE_END 0xdfff
  2680. #endif
  2681. /* These macros exist in the Windows API, so the environment may
  2682. * provide them. If not, define them in terms of the above. */
  2683. #ifndef IS_HIGH_SURROGATE
  2684. #define IS_HIGH_SURROGATE(wch) (((wch) >= HIGH_SURROGATE_START) && \
  2685. ((wch) <= HIGH_SURROGATE_END))
  2686. #define IS_LOW_SURROGATE(wch) (((wch) >= LOW_SURROGATE_START) && \
  2687. ((wch) <= LOW_SURROGATE_END))
  2688. #define IS_SURROGATE_PAIR(hs, ls) (IS_HIGH_SURROGATE(hs) && \
  2689. IS_LOW_SURROGATE(ls))
  2690. #endif
  2691. #define IS_SURROGATE(wch) (((wch) >= HIGH_SURROGATE_START) && \
  2692. ((wch) <= LOW_SURROGATE_END))
  2693. #define HIGH_SURROGATE_OF(codept) \
  2694. (HIGH_SURROGATE_START + (((codept) - 0x10000) >> 10))
  2695. #define LOW_SURROGATE_OF(codept) \
  2696. (LOW_SURROGATE_START + (((codept) - 0x10000) & 0x3FF))
  2697. #define FROM_SURROGATES(wch1, wch2) \
  2698. (0x10000 + (((wch1) & 0x3FF) << 10) + ((wch2) & 0x3FF))
  2699. #endif