putty.h 96 KB

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