putty.h 115 KB

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