putty.h 117 KB

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