putty.h 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537
  1. #ifndef PUTTY_PUTTY_H
  2. #define PUTTY_PUTTY_H
  3. #include <stddef.h> /* for wchar_t */
  4. /*
  5. * Global variables. Most modules declare these `extern', but
  6. * window.c will do `#define PUTTY_DO_GLOBALS' before including this
  7. * module, and so will get them properly defined.
  8. */
  9. #ifndef GLOBAL
  10. #ifdef PUTTY_DO_GLOBALS
  11. #define GLOBAL
  12. #else
  13. #define GLOBAL extern
  14. #endif
  15. #endif
  16. #ifndef DONE_TYPEDEFS
  17. #define DONE_TYPEDEFS
  18. typedef struct conf_tag Conf;
  19. typedef struct backend_tag Backend;
  20. typedef struct terminal_tag Terminal;
  21. #endif
  22. #include "puttyps.h"
  23. #include "network.h"
  24. #include "misc.h"
  25. /*
  26. * Fingerprints of the PGP master keys that can be used to establish a trust
  27. * path between an executable and other files.
  28. */
  29. #define PGP_MASTER_KEY_FP \
  30. "440D E3B5 B7A1 CA85 B3CC 1718 AB58 5DC6 0467 6F7C"
  31. #define PGP_RSA_MASTER_KEY_FP \
  32. "8F 15 97 DA 25 30 AB 0D 88 D1 92 54 11 CF 0C 4C"
  33. #define PGP_DSA_MASTER_KEY_FP \
  34. "313C 3E76 4B74 C2C5 F2AE 83A8 4F5E 6DF5 6A93 B34E"
  35. /* Three attribute types:
  36. * The ATTRs (normal attributes) are stored with the characters in
  37. * the main display arrays
  38. *
  39. * The TATTRs (temporary attributes) are generated on the fly, they
  40. * can overlap with characters but not with normal attributes.
  41. *
  42. * The LATTRs (line attributes) are an entirely disjoint space of
  43. * flags.
  44. *
  45. * The DATTRs (display attributes) are internal to terminal.c (but
  46. * defined here because their values have to match the others
  47. * here); they reuse the TATTR_* space but are always masked off
  48. * before sending to the front end.
  49. *
  50. * ATTR_INVALID is an illegal colour combination.
  51. */
  52. #define TATTR_ACTCURS 0x40000000UL /* active cursor (block) */
  53. #define TATTR_PASCURS 0x20000000UL /* passive cursor (box) */
  54. #define TATTR_RIGHTCURS 0x10000000UL /* cursor-on-RHS */
  55. #define TATTR_COMBINING 0x80000000UL /* combining characters */
  56. #define DATTR_STARTRUN 0x80000000UL /* start of redraw run */
  57. #define TDATTR_MASK 0xF0000000UL
  58. #define TATTR_MASK (TDATTR_MASK)
  59. #define DATTR_MASK (TDATTR_MASK)
  60. #define LATTR_NORM 0x00000000UL
  61. #define LATTR_WIDE 0x00000001UL
  62. #define LATTR_TOP 0x00000002UL
  63. #define LATTR_BOT 0x00000003UL
  64. #define LATTR_MODE 0x00000003UL
  65. #define LATTR_WRAPPED 0x00000010UL /* this line wraps to next */
  66. #define LATTR_WRAPPED2 0x00000020UL /* with WRAPPED: CJK wide character
  67. wrapped to next line, so last
  68. single-width cell is empty */
  69. #define ATTR_INVALID 0x03FFFFU
  70. /* Like Linux use the F000 page for direct to font. */
  71. #define CSET_OEMCP 0x0000F000UL /* OEM Codepage DTF */
  72. #define CSET_ACP 0x0000F100UL /* Ansi Codepage DTF */
  73. /* These are internal use overlapping with the UTF-16 surrogates */
  74. #define CSET_ASCII 0x0000D800UL /* normal ASCII charset ESC ( B */
  75. #define CSET_LINEDRW 0x0000D900UL /* line drawing charset ESC ( 0 */
  76. #define CSET_SCOACS 0x0000DA00UL /* SCO Alternate charset */
  77. #define CSET_GBCHR 0x0000DB00UL /* UK variant charset ESC ( A */
  78. #define CSET_MASK 0xFFFFFF00UL /* Character set mask */
  79. #define DIRECT_CHAR(c) ((c&0xFFFFFC00)==0xD800)
  80. #define DIRECT_FONT(c) ((c&0xFFFFFE00)==0xF000)
  81. #define UCSERR (CSET_LINEDRW|'a') /* UCS Format error character. */
  82. /*
  83. * UCSWIDE is a special value used in the terminal data to signify
  84. * the character cell containing the right-hand half of a CJK wide
  85. * character. We use 0xDFFF because it's part of the surrogate
  86. * range and hence won't be used for anything else (it's impossible
  87. * to input it via UTF-8 because our UTF-8 decoder correctly
  88. * rejects surrogates).
  89. */
  90. #define UCSWIDE 0xDFFF
  91. #define ATTR_NARROW 0x800000U
  92. #define ATTR_WIDE 0x400000U
  93. #define ATTR_BOLD 0x040000U
  94. #define ATTR_UNDER 0x080000U
  95. #define ATTR_REVERSE 0x100000U
  96. #define ATTR_BLINK 0x200000U
  97. #define ATTR_FGMASK 0x0001FFU
  98. #define ATTR_BGMASK 0x03FE00U
  99. #define ATTR_COLOURS 0x03FFFFU
  100. #define ATTR_FGSHIFT 0
  101. #define ATTR_BGSHIFT 9
  102. /*
  103. * The definitive list of colour numbers stored in terminal
  104. * attribute words is kept here. It is:
  105. *
  106. * - 0-7 are ANSI colours (KRGYBMCW).
  107. * - 8-15 are the bold versions of those colours.
  108. * - 16-255 are the remains of the xterm 256-colour mode (a
  109. * 216-colour cube with R at most significant and B at least,
  110. * followed by a uniform series of grey shades running between
  111. * black and white but not including either on grounds of
  112. * redundancy).
  113. * - 256 is default foreground
  114. * - 257 is default bold foreground
  115. * - 258 is default background
  116. * - 259 is default bold background
  117. * - 260 is cursor foreground
  118. * - 261 is cursor background
  119. */
  120. #define ATTR_DEFFG (256 << ATTR_FGSHIFT)
  121. #define ATTR_DEFBG (258 << ATTR_BGSHIFT)
  122. #define ATTR_DEFAULT (ATTR_DEFFG | ATTR_DEFBG)
  123. struct sesslist {
  124. int nsessions;
  125. const char **sessions;
  126. char *buffer; /* so memory can be freed later */
  127. };
  128. struct unicode_data {
  129. char **uni_tbl;
  130. int dbcs_screenfont;
  131. int font_codepage;
  132. int line_codepage;
  133. wchar_t unitab_scoacs[256];
  134. wchar_t unitab_line[256];
  135. wchar_t unitab_font[256];
  136. wchar_t unitab_xterm[256];
  137. wchar_t unitab_oemcp[256];
  138. unsigned char unitab_ctrl[256];
  139. };
  140. #define LGXF_OVR 1 /* existing logfile overwrite */
  141. #define LGXF_APN 0 /* existing logfile append */
  142. #define LGXF_ASK -1 /* existing logfile ask */
  143. #define LGTYP_NONE 0 /* logmode: no logging */
  144. #define LGTYP_ASCII 1 /* logmode: pure ascii */
  145. #define LGTYP_DEBUG 2 /* logmode: all chars of traffic */
  146. #define LGTYP_PACKETS 3 /* logmode: SSH data packets */
  147. #define LGTYP_SSHRAW 4 /* logmode: SSH raw data */
  148. typedef enum {
  149. /* Actual special commands. Originally Telnet, but some codes have
  150. * been re-used for similar specials in other protocols. */
  151. TS_AYT, TS_BRK, TS_SYNCH, TS_EC, TS_EL, TS_GA, TS_NOP, TS_ABORT,
  152. TS_AO, TS_IP, TS_SUSP, TS_EOR, TS_EOF, TS_LECHO, TS_RECHO, TS_PING,
  153. TS_EOL,
  154. /* Special command for SSH. */
  155. TS_REKEY,
  156. /* POSIX-style signals. (not Telnet) */
  157. TS_SIGABRT, TS_SIGALRM, TS_SIGFPE, TS_SIGHUP, TS_SIGILL,
  158. TS_SIGINT, TS_SIGKILL, TS_SIGPIPE, TS_SIGQUIT, TS_SIGSEGV,
  159. TS_SIGTERM, TS_SIGUSR1, TS_SIGUSR2,
  160. /* Pseudo-specials used for constructing the specials menu. */
  161. TS_SEP, /* Separator */
  162. TS_SUBMENU, /* Start a new submenu with specified name */
  163. TS_EXITMENU, /* Exit current submenu or end of specials */
  164. /* Starting point for protocols to invent special-action codes
  165. * that can't live in this enum at all, e.g. because they change
  166. * with every session.
  167. *
  168. * Of course, this must remain the last value in this
  169. * enumeration. */
  170. TS_LOCALSTART
  171. } Telnet_Special;
  172. struct telnet_special {
  173. const char *name;
  174. int code;
  175. };
  176. typedef enum {
  177. MBT_NOTHING,
  178. MBT_LEFT, MBT_MIDDLE, MBT_RIGHT, /* `raw' button designations */
  179. MBT_SELECT, MBT_EXTEND, MBT_PASTE, /* `cooked' button designations */
  180. MBT_WHEEL_UP, MBT_WHEEL_DOWN /* mouse wheel */
  181. } Mouse_Button;
  182. typedef enum {
  183. MA_NOTHING, MA_CLICK, MA_2CLK, MA_3CLK, MA_DRAG, MA_RELEASE
  184. } Mouse_Action;
  185. /* Keyboard modifiers -- keys the user is actually holding down */
  186. #define PKM_SHIFT 0x01
  187. #define PKM_CONTROL 0x02
  188. #define PKM_META 0x04
  189. #define PKM_ALT 0x08
  190. /* Keyboard flags that aren't really modifiers */
  191. #define PKF_CAPSLOCK 0x10
  192. #define PKF_NUMLOCK 0x20
  193. #define PKF_REPEAT 0x40
  194. /* Stand-alone keysyms for function keys */
  195. typedef enum {
  196. PK_NULL, /* No symbol for this key */
  197. /* Main keypad keys */
  198. PK_ESCAPE, PK_TAB, PK_BACKSPACE, PK_RETURN, PK_COMPOSE,
  199. /* Editing keys */
  200. PK_HOME, PK_INSERT, PK_DELETE, PK_END, PK_PAGEUP, PK_PAGEDOWN,
  201. /* Cursor keys */
  202. PK_UP, PK_DOWN, PK_RIGHT, PK_LEFT, PK_REST,
  203. /* Numeric keypad */ /* Real one looks like: */
  204. PK_PF1, PK_PF2, PK_PF3, PK_PF4, /* PF1 PF2 PF3 PF4 */
  205. PK_KPCOMMA, PK_KPMINUS, PK_KPDECIMAL, /* 7 8 9 - */
  206. PK_KP0, PK_KP1, PK_KP2, PK_KP3, PK_KP4, /* 4 5 6 , */
  207. PK_KP5, PK_KP6, PK_KP7, PK_KP8, PK_KP9, /* 1 2 3 en- */
  208. PK_KPBIGPLUS, PK_KPENTER, /* 0 . ter */
  209. /* Top row */
  210. PK_F1, PK_F2, PK_F3, PK_F4, PK_F5,
  211. PK_F6, PK_F7, PK_F8, PK_F9, PK_F10,
  212. PK_F11, PK_F12, PK_F13, PK_F14, PK_F15,
  213. PK_F16, PK_F17, PK_F18, PK_F19, PK_F20,
  214. PK_PAUSE
  215. } Key_Sym;
  216. #define PK_ISEDITING(k) ((k) >= PK_HOME && (k) <= PK_PAGEDOWN)
  217. #define PK_ISCURSOR(k) ((k) >= PK_UP && (k) <= PK_REST)
  218. #define PK_ISKEYPAD(k) ((k) >= PK_PF1 && (k) <= PK_KPENTER)
  219. #define PK_ISFKEY(k) ((k) >= PK_F1 && (k) <= PK_F20)
  220. enum {
  221. VT_XWINDOWS, VT_OEMANSI, VT_OEMONLY, VT_POORMAN, VT_UNICODE
  222. };
  223. enum {
  224. /*
  225. * SSH-2 key exchange algorithms
  226. */
  227. KEX_WARN,
  228. KEX_DHGROUP1,
  229. KEX_DHGROUP14,
  230. KEX_DHGEX,
  231. KEX_RSA,
  232. KEX_ECDH,
  233. KEX_MAX
  234. };
  235. enum {
  236. /*
  237. * SSH-2 host key algorithms
  238. */
  239. HK_WARN,
  240. HK_RSA,
  241. HK_DSA,
  242. HK_ECDSA,
  243. HK_ED25519,
  244. HK_MAX
  245. };
  246. enum {
  247. /*
  248. * SSH ciphers (both SSH-1 and SSH-2)
  249. */
  250. CIPHER_WARN, /* pseudo 'cipher' */
  251. CIPHER_3DES,
  252. CIPHER_BLOWFISH,
  253. CIPHER_AES, /* (SSH-2 only) */
  254. CIPHER_DES,
  255. CIPHER_ARCFOUR,
  256. CIPHER_CHACHA20,
  257. CIPHER_MAX /* no. ciphers (inc warn) */
  258. };
  259. enum {
  260. /*
  261. * Several different bits of the PuTTY configuration seem to be
  262. * three-way settings whose values are `always yes', `always
  263. * no', and `decide by some more complex automated means'. This
  264. * is true of line discipline options (local echo and line
  265. * editing), proxy DNS, proxy terminal logging, Close On Exit, and
  266. * SSH server bug workarounds. Accordingly I supply a single enum
  267. * here to deal with them all.
  268. */
  269. FORCE_ON, FORCE_OFF, AUTO
  270. };
  271. enum {
  272. /*
  273. * Proxy types.
  274. */
  275. PROXY_NONE, PROXY_SOCKS4, PROXY_SOCKS5,
  276. PROXY_HTTP, PROXY_TELNET, PROXY_CMD, PROXY_FUZZ
  277. };
  278. enum {
  279. /*
  280. * Line discipline options which the backend might try to control.
  281. */
  282. LD_EDIT, /* local line editing */
  283. LD_ECHO /* local echo */
  284. };
  285. enum {
  286. /* Actions on remote window title query */
  287. TITLE_NONE, TITLE_EMPTY, TITLE_REAL
  288. };
  289. enum {
  290. /* Protocol back ends. (CONF_protocol) */
  291. PROT_RAW, PROT_TELNET, PROT_RLOGIN, PROT_SSH,
  292. /* PROT_SERIAL is supported on a subset of platforms, but it doesn't
  293. * hurt to define it globally. */
  294. PROT_SERIAL
  295. };
  296. enum {
  297. /* Bell settings (CONF_beep) */
  298. BELL_DISABLED, BELL_DEFAULT, BELL_VISUAL, BELL_WAVEFILE, BELL_PCSPEAKER
  299. };
  300. enum {
  301. /* Taskbar flashing indication on bell (CONF_beep_ind) */
  302. B_IND_DISABLED, B_IND_FLASH, B_IND_STEADY
  303. };
  304. enum {
  305. /* Resize actions (CONF_resize_action) */
  306. RESIZE_TERM, RESIZE_DISABLED, RESIZE_FONT, RESIZE_EITHER
  307. };
  308. enum {
  309. /* Function key types (CONF_funky_type) */
  310. FUNKY_TILDE,
  311. FUNKY_LINUX,
  312. FUNKY_XTERM,
  313. FUNKY_VT400,
  314. FUNKY_VT100P,
  315. FUNKY_SCO
  316. };
  317. enum {
  318. FQ_DEFAULT, FQ_ANTIALIASED, FQ_NONANTIALIASED, FQ_CLEARTYPE
  319. };
  320. enum {
  321. SER_PAR_NONE, SER_PAR_ODD, SER_PAR_EVEN, SER_PAR_MARK, SER_PAR_SPACE
  322. };
  323. enum {
  324. SER_FLOW_NONE, SER_FLOW_XONXOFF, SER_FLOW_RTSCTS, SER_FLOW_DSRDTR
  325. };
  326. /*
  327. * Tables of string <-> enum value mappings used in settings.c.
  328. * Defined here so that backends can export their GSS library tables
  329. * to the cross-platform settings code.
  330. */
  331. struct keyvalwhere {
  332. /*
  333. * Two fields which define a string and enum value to be
  334. * equivalent to each other.
  335. */
  336. const char *s;
  337. int v;
  338. /*
  339. * The next pair of fields are used by gprefs() in settings.c to
  340. * arrange that when it reads a list of strings representing a
  341. * preference list and translates it into the corresponding list
  342. * of integers, strings not appearing in the list are entered in a
  343. * configurable position rather than uniformly at the end.
  344. */
  345. /*
  346. * 'vrel' indicates which other value in the list to place this
  347. * element relative to. It should be a value that has occurred in
  348. * a 'v' field of some other element of the array, or -1 to
  349. * indicate that we simply place relative to one or other end of
  350. * the list.
  351. *
  352. * gprefs will try to process the elements in an order which makes
  353. * this field work (i.e. so that the element referenced has been
  354. * added before processing this one).
  355. */
  356. int vrel;
  357. /*
  358. * 'where' indicates whether to place the new value before or
  359. * after the one referred to by vrel. -1 means before; +1 means
  360. * after.
  361. *
  362. * When vrel is -1, this also implicitly indicates which end of
  363. * the array to use. So vrel=-1, where=-1 means to place _before_
  364. * some end of the list (hence, at the last element); vrel=-1,
  365. * where=+1 means to place _after_ an end (hence, at the first).
  366. */
  367. int where;
  368. };
  369. #ifndef NO_GSSAPI
  370. extern const int ngsslibs;
  371. extern const char *const gsslibnames[]; /* for displaying in configuration */
  372. extern const struct keyvalwhere gsslibkeywords[]; /* for settings.c */
  373. #endif
  374. extern const char *const ttymodes[];
  375. enum {
  376. /*
  377. * Network address types. Used for specifying choice of IPv4/v6
  378. * in config; also used in proxy.c to indicate whether a given
  379. * host name has already been resolved or will be resolved at
  380. * the proxy end.
  381. */
  382. ADDRTYPE_UNSPEC, ADDRTYPE_IPV4, ADDRTYPE_IPV6, ADDRTYPE_NAME
  383. };
  384. struct backend_tag {
  385. const char *(*init) (void *frontend_handle, void **backend_handle,
  386. Conf *conf, const char *host, int port,
  387. char **realhost, int nodelay, int keepalive);
  388. void (*free) (void *handle);
  389. /* back->reconfig() passes in a replacement configuration. */
  390. void (*reconfig) (void *handle, Conf *conf);
  391. /* back->send() returns the current amount of buffered data. */
  392. int (*send) (void *handle, const char *buf, int len);
  393. /* back->sendbuffer() does the same thing but without attempting a send */
  394. int (*sendbuffer) (void *handle);
  395. void (*size) (void *handle, int width, int height);
  396. void (*special) (void *handle, Telnet_Special code);
  397. const struct telnet_special *(*get_specials) (void *handle);
  398. int (*connected) (void *handle);
  399. int (*exitcode) (void *handle);
  400. /* If back->sendok() returns FALSE, data sent to it from the frontend
  401. * may be lost. */
  402. int (*sendok) (void *handle);
  403. int (*ldisc) (void *handle, int);
  404. void (*provide_ldisc) (void *handle, void *ldisc);
  405. void (*provide_logctx) (void *handle, void *logctx);
  406. /*
  407. * back->unthrottle() tells the back end that the front end
  408. * buffer is clearing.
  409. */
  410. void (*unthrottle) (void *handle, int);
  411. int (*cfg_info) (void *handle);
  412. /* Only implemented in the SSH protocol: check whether a
  413. * connection-sharing upstream exists for a given configuration. */
  414. int (*test_for_upstream)(const char *host, int port, Conf *conf);
  415. const char *name;
  416. int protocol;
  417. int default_port;
  418. };
  419. extern Backend *backends[];
  420. /*
  421. * Suggested default protocol provided by the backend link module.
  422. * The application is free to ignore this.
  423. */
  424. extern const int be_default_protocol;
  425. /*
  426. * Name of this particular application, for use in the config box
  427. * and other pieces of text.
  428. */
  429. extern const char *const appname;
  430. /*
  431. * Some global flags denoting the type of application.
  432. *
  433. * FLAG_VERBOSE is set when the user requests verbose details.
  434. *
  435. * FLAG_STDERR is set in command-line applications (which have a
  436. * functioning stderr that it makes sense to write to) and not in
  437. * GUI applications (which don't).
  438. *
  439. * FLAG_INTERACTIVE is set when a full interactive shell session is
  440. * being run, _either_ because no remote command has been provided
  441. * _or_ because the application is GUI and can't run non-
  442. * interactively.
  443. *
  444. * These flags describe the type of _application_ - they wouldn't
  445. * vary between individual sessions - and so it's OK to have this
  446. * variable be GLOBAL.
  447. *
  448. * Note that additional flags may be defined in platform-specific
  449. * headers. It's probably best if those ones start from 0x1000, to
  450. * avoid collision.
  451. */
  452. #define FLAG_VERBOSE 0x0001
  453. #define FLAG_STDERR 0x0002
  454. #define FLAG_INTERACTIVE 0x0004
  455. GLOBAL int flags;
  456. /*
  457. * Likewise, these two variables are set up when the application
  458. * initialises, and inform all default-settings accesses after
  459. * that.
  460. */
  461. GLOBAL int default_protocol;
  462. GLOBAL int default_port;
  463. /*
  464. * This is set TRUE by cmdline.c iff a session is loaded with "-load".
  465. */
  466. GLOBAL int loaded_session;
  467. /*
  468. * This is set to the name of the loaded session.
  469. */
  470. GLOBAL char *cmdline_session_name;
  471. struct RSAKey; /* be a little careful of scope */
  472. /*
  473. * Mechanism for getting text strings such as usernames and passwords
  474. * from the front-end.
  475. * The fields are mostly modelled after SSH's keyboard-interactive auth.
  476. * FIXME We should probably mandate a character set/encoding (probably UTF-8).
  477. *
  478. * Since many of the pieces of text involved may be chosen by the server,
  479. * the caller must take care to ensure that the server can't spoof locally-
  480. * generated prompts such as key passphrase prompts. Some ground rules:
  481. * - If the front-end needs to truncate a string, it should lop off the
  482. * end.
  483. * - The front-end should filter out any dangerous characters and
  484. * generally not trust the strings. (But \n is required to behave
  485. * vaguely sensibly, at least in `instruction', and ideally in
  486. * `prompt[]' too.)
  487. */
  488. typedef struct {
  489. char *prompt;
  490. int echo;
  491. /*
  492. * 'result' must be a dynamically allocated array of exactly
  493. * 'resultsize' chars. The code for actually reading input may
  494. * realloc it bigger (and adjust resultsize accordingly) if it has
  495. * to. The caller should free it again when finished with it.
  496. *
  497. * If resultsize==0, then result may be NULL. When setting up a
  498. * prompt_t, it's therefore easiest to initialise them this way,
  499. * which means all actual allocation is done by the callee. This
  500. * is what add_prompt does.
  501. */
  502. char *result;
  503. size_t resultsize;
  504. } prompt_t;
  505. typedef struct {
  506. /*
  507. * Indicates whether the information entered is to be used locally
  508. * (for instance a key passphrase prompt), or is destined for the wire.
  509. * This is a hint only; the front-end is at liberty not to use this
  510. * information (so the caller should ensure that the supplied text is
  511. * sufficient).
  512. */
  513. int to_server;
  514. char *name; /* Short description, perhaps for dialog box title */
  515. int name_reqd; /* Display of `name' required or optional? */
  516. char *instruction; /* Long description, maybe with embedded newlines */
  517. int instr_reqd; /* Display of `instruction' required or optional? */
  518. size_t n_prompts; /* May be zero (in which case display the foregoing,
  519. * if any, and return success) */
  520. prompt_t **prompts;
  521. void *frontend;
  522. void *data; /* slot for housekeeping data, managed by
  523. * get_userpass_input(); initially NULL */
  524. } prompts_t;
  525. prompts_t *new_prompts(void *frontend);
  526. void add_prompt(prompts_t *p, char *promptstr, int echo);
  527. void prompt_set_result(prompt_t *pr, const char *newstr);
  528. void prompt_ensure_result_size(prompt_t *pr, int len);
  529. /* Burn the evidence. (Assumes _all_ strings want free()ing.) */
  530. void free_prompts(prompts_t *p);
  531. /*
  532. * Exports from the front end.
  533. */
  534. void request_resize(void *frontend, int, int);
  535. void do_text(Context, int, int, wchar_t *, int, unsigned long, int);
  536. void do_cursor(Context, int, int, wchar_t *, int, unsigned long, int);
  537. int char_width(Context ctx, int uc);
  538. #ifdef OPTIMISE_SCROLL
  539. void do_scroll(Context, int, int, int);
  540. #endif
  541. void set_title(void *frontend, char *);
  542. void set_icon(void *frontend, char *);
  543. void set_sbar(void *frontend, int, int, int);
  544. Context get_ctx(void *frontend);
  545. void free_ctx(Context);
  546. void palette_set(void *frontend, int, int, int, int);
  547. void palette_reset(void *frontend);
  548. void write_aclip(void *frontend, char *, int, int);
  549. void write_clip(void *frontend, wchar_t *, int *, int, int);
  550. void get_clip(void *frontend, wchar_t **, int *);
  551. void optimised_move(void *frontend, int, int, int);
  552. void set_raw_mouse_mode(void *frontend, int);
  553. void connection_fatal(void *frontend, const char *, ...);
  554. void nonfatal(const char *, ...);
  555. void fatalbox(const char *, ...);
  556. void modalfatalbox(const char *, ...);
  557. #ifdef macintosh
  558. #pragma noreturn(fatalbox)
  559. #pragma noreturn(modalfatalbox)
  560. #endif
  561. void do_beep(void *frontend, int);
  562. void begin_session(void *frontend);
  563. void sys_cursor(void *frontend, int x, int y);
  564. void request_paste(void *frontend);
  565. void frontend_keypress(void *frontend);
  566. void frontend_echoedit_update(void *frontend, int echo, int edit);
  567. /* It's the backend's responsibility to invoke this at the start of a
  568. * connection, if necessary; it can also invoke it later if the set of
  569. * special commands changes. It does not need to invoke it at session
  570. * shutdown. */
  571. void update_specials_menu(void *frontend);
  572. int from_backend(void *frontend, int is_stderr, const char *data, int len);
  573. int from_backend_untrusted(void *frontend, const char *data, int len);
  574. /* Called when the back end wants to indicate that EOF has arrived on
  575. * the server-to-client stream. Returns FALSE to indicate that we
  576. * intend to keep the session open in the other direction, or TRUE to
  577. * indicate that if they're closing so are we. */
  578. int from_backend_eof(void *frontend);
  579. void notify_remote_exit(void *frontend);
  580. /* Get a sensible value for a tty mode. NULL return = don't set.
  581. * Otherwise, returned value should be freed by caller. */
  582. char *get_ttymode(void *frontend, const char *mode);
  583. /*
  584. * >0 = `got all results, carry on'
  585. * 0 = `user cancelled' (FIXME distinguish "give up entirely" and "next auth"?)
  586. * <0 = `please call back later with more in/inlen'
  587. */
  588. int get_userpass_input(prompts_t *p, const unsigned char *in, int inlen);
  589. #define OPTIMISE_IS_SCROLL 1
  590. void set_iconic(void *frontend, int iconic);
  591. void move_window(void *frontend, int x, int y);
  592. void set_zorder(void *frontend, int top);
  593. void refresh_window(void *frontend);
  594. void set_zoomed(void *frontend, int zoomed);
  595. int is_iconic(void *frontend);
  596. void get_window_pos(void *frontend, int *x, int *y);
  597. void get_window_pixels(void *frontend, int *x, int *y);
  598. char *get_window_title(void *frontend, int icon);
  599. /* Hint from backend to frontend about time-consuming operations.
  600. * Initial state is assumed to be BUSY_NOT. */
  601. enum {
  602. BUSY_NOT, /* Not busy, all user interaction OK */
  603. BUSY_WAITING, /* Waiting for something; local event loops still running
  604. so some local interaction (e.g. menus) OK, but network
  605. stuff is suspended */
  606. BUSY_CPU /* Locally busy (e.g. crypto); user interaction suspended */
  607. };
  608. void set_busy_status(void *frontend, int status);
  609. void cleanup_exit(int);
  610. /*
  611. * Exports from conf.c, and a big enum (via parametric macro) of
  612. * configuration option keys.
  613. */
  614. #define CONFIG_OPTIONS(X) \
  615. /* X(value-type, subkey-type, keyword) */ \
  616. X(STR, NONE, host) \
  617. X(INT, NONE, port) \
  618. X(INT, NONE, protocol) \
  619. X(INT, NONE, addressfamily) \
  620. X(INT, NONE, close_on_exit) \
  621. X(INT, NONE, warn_on_close) \
  622. X(INT, NONE, ping_interval) /* in seconds */ \
  623. X(INT, NONE, tcp_nodelay) \
  624. X(INT, NONE, tcp_keepalives) \
  625. X(STR, NONE, loghost) /* logical host being contacted, for host key check */ \
  626. /* Proxy options */ \
  627. X(STR, NONE, proxy_exclude_list) \
  628. X(INT, NONE, proxy_dns) \
  629. X(INT, NONE, even_proxy_localhost) \
  630. X(INT, NONE, proxy_type) \
  631. X(STR, NONE, proxy_host) \
  632. X(INT, NONE, proxy_port) \
  633. X(STR, NONE, proxy_username) \
  634. X(STR, NONE, proxy_password) \
  635. X(STR, NONE, proxy_telnet_command) \
  636. X(INT, NONE, proxy_log_to_term) \
  637. /* SSH options */ \
  638. X(STR, NONE, remote_cmd) \
  639. X(STR, NONE, remote_cmd2) /* fallback if remote_cmd fails; never loaded or saved */ \
  640. X(INT, NONE, nopty) \
  641. X(INT, NONE, compression) \
  642. X(INT, INT, ssh_kexlist) \
  643. X(INT, INT, ssh_hklist) \
  644. X(INT, NONE, ssh_rekey_time) /* in minutes */ \
  645. X(STR, NONE, ssh_rekey_data) /* string encoding e.g. "100K", "2M", "1G" */ \
  646. X(INT, NONE, tryagent) \
  647. X(INT, NONE, agentfwd) \
  648. X(INT, NONE, change_username) /* allow username switching in SSH-2 */ \
  649. X(INT, INT, ssh_cipherlist) \
  650. X(FILENAME, NONE, keyfile) \
  651. /* \
  652. * Which SSH protocol to use. \
  653. * For historical reasons, the current legal values for CONF_sshprot \
  654. * are: \
  655. * 0 = SSH-1 only \
  656. * 3 = SSH-2 only \
  657. * We used to also support \
  658. * 1 = SSH-1 with fallback to SSH-2 \
  659. * 2 = SSH-2 with fallback to SSH-1 \
  660. * and we continue to use 0/3 in storage formats rather than the more \
  661. * obvious 1/2 to avoid surprises if someone saves a session and later \
  662. * downgrades PuTTY. So it's easier to use these numbers internally too. \
  663. */ \
  664. X(INT, NONE, sshprot) \
  665. X(INT, NONE, ssh2_des_cbc) /* "des-cbc" unrecommended SSH-2 cipher */ \
  666. X(INT, NONE, ssh_no_userauth) /* bypass "ssh-userauth" (SSH-2 only) */ \
  667. X(INT, NONE, ssh_show_banner) /* show USERAUTH_BANNERs (SSH-2 only) */ \
  668. X(INT, NONE, try_tis_auth) \
  669. X(INT, NONE, try_ki_auth) \
  670. X(INT, NONE, try_gssapi_auth) /* attempt gssapi auth */ \
  671. X(INT, NONE, gssapifwd) /* forward tgt via gss */ \
  672. X(INT, INT, ssh_gsslist) /* preference order for local GSS libs */ \
  673. X(FILENAME, NONE, ssh_gss_custom) \
  674. X(INT, NONE, ssh_subsys) /* run a subsystem rather than a command */ \
  675. X(INT, NONE, ssh_subsys2) /* fallback to go with remote_cmd_ptr2 */ \
  676. X(INT, NONE, ssh_no_shell) /* avoid running a shell */ \
  677. X(STR, NONE, ssh_nc_host) /* host to connect to in `nc' mode */ \
  678. X(INT, NONE, ssh_nc_port) /* port to connect to in `nc' mode */ \
  679. /* Telnet options */ \
  680. X(STR, NONE, termtype) \
  681. X(STR, NONE, termspeed) \
  682. X(STR, STR, ttymodes) /* values are "Vvalue" or "A" */ \
  683. X(STR, STR, environmt) \
  684. X(STR, NONE, username) \
  685. X(INT, NONE, username_from_env) \
  686. X(STR, NONE, localusername) \
  687. X(INT, NONE, rfc_environ) \
  688. X(INT, NONE, passive_telnet) \
  689. /* Serial port options */ \
  690. X(STR, NONE, serline) \
  691. X(INT, NONE, serspeed) \
  692. X(INT, NONE, serdatabits) \
  693. X(INT, NONE, serstopbits) \
  694. X(INT, NONE, serparity) \
  695. X(INT, NONE, serflow) \
  696. /* Keyboard options */ \
  697. X(INT, NONE, bksp_is_delete) \
  698. X(INT, NONE, rxvt_homeend) \
  699. X(INT, NONE, funky_type) \
  700. X(INT, NONE, no_applic_c) /* totally disable app cursor keys */ \
  701. X(INT, NONE, no_applic_k) /* totally disable app keypad */ \
  702. X(INT, NONE, no_mouse_rep) /* totally disable mouse reporting */ \
  703. X(INT, NONE, no_remote_resize) /* disable remote resizing */ \
  704. X(INT, NONE, no_alt_screen) /* disable alternate screen */ \
  705. X(INT, NONE, no_remote_wintitle) /* disable remote retitling */ \
  706. X(INT, NONE, no_dbackspace) /* disable destructive backspace */ \
  707. X(INT, NONE, no_remote_charset) /* disable remote charset config */ \
  708. X(INT, NONE, remote_qtitle_action) /* remote win title query action */ \
  709. X(INT, NONE, app_cursor) \
  710. X(INT, NONE, app_keypad) \
  711. X(INT, NONE, nethack_keypad) \
  712. X(INT, NONE, telnet_keyboard) \
  713. X(INT, NONE, telnet_newline) \
  714. X(INT, NONE, alt_f4) /* is it special? */ \
  715. X(INT, NONE, alt_space) /* is it special? */ \
  716. X(INT, NONE, alt_only) /* is it special? */ \
  717. X(INT, NONE, localecho) \
  718. X(INT, NONE, localedit) \
  719. X(INT, NONE, alwaysontop) \
  720. X(INT, NONE, fullscreenonaltenter) \
  721. X(INT, NONE, scroll_on_key) \
  722. X(INT, NONE, scroll_on_disp) \
  723. X(INT, NONE, erase_to_scrollback) \
  724. X(INT, NONE, compose_key) \
  725. X(INT, NONE, ctrlaltkeys) \
  726. X(INT, NONE, osx_option_meta) \
  727. X(INT, NONE, osx_command_meta) \
  728. X(STR, NONE, wintitle) /* initial window title */ \
  729. /* Terminal options */ \
  730. X(INT, NONE, savelines) \
  731. X(INT, NONE, dec_om) \
  732. X(INT, NONE, wrap_mode) \
  733. X(INT, NONE, lfhascr) \
  734. X(INT, NONE, cursor_type) /* 0=block 1=underline 2=vertical */ \
  735. X(INT, NONE, blink_cur) \
  736. X(INT, NONE, beep) \
  737. X(INT, NONE, beep_ind) \
  738. X(INT, NONE, bellovl) /* bell overload protection active? */ \
  739. X(INT, NONE, bellovl_n) /* number of bells to cause overload */ \
  740. X(INT, NONE, bellovl_t) /* time interval for overload (seconds) */ \
  741. X(INT, NONE, bellovl_s) /* period of silence to re-enable bell (s) */ \
  742. X(FILENAME, NONE, bell_wavefile) \
  743. X(INT, NONE, scrollbar) \
  744. X(INT, NONE, scrollbar_in_fullscreen) \
  745. X(INT, NONE, resize_action) \
  746. X(INT, NONE, bce) \
  747. X(INT, NONE, blinktext) \
  748. X(INT, NONE, win_name_always) \
  749. X(INT, NONE, width) \
  750. X(INT, NONE, height) \
  751. X(FONT, NONE, font) \
  752. X(INT, NONE, font_quality) \
  753. X(FILENAME, NONE, logfilename) \
  754. X(INT, NONE, logtype) \
  755. X(INT, NONE, logxfovr) \
  756. X(INT, NONE, logflush) \
  757. X(INT, NONE, logomitpass) \
  758. X(INT, NONE, logomitdata) \
  759. X(INT, NONE, hide_mouseptr) \
  760. X(INT, NONE, sunken_edge) \
  761. X(INT, NONE, window_border) \
  762. X(STR, NONE, answerback) \
  763. X(STR, NONE, printer) \
  764. X(INT, NONE, arabicshaping) \
  765. X(INT, NONE, bidi) \
  766. /* Colour options */ \
  767. X(INT, NONE, ansi_colour) \
  768. X(INT, NONE, xterm_256_colour) \
  769. X(INT, NONE, system_colour) \
  770. X(INT, NONE, try_palette) \
  771. X(INT, NONE, bold_style) \
  772. X(INT, INT, colours) \
  773. /* Selection options */ \
  774. X(INT, NONE, mouse_is_xterm) \
  775. X(INT, NONE, rect_select) \
  776. X(INT, NONE, rawcnp) \
  777. X(INT, NONE, rtf_paste) \
  778. X(INT, NONE, mouse_override) \
  779. X(INT, INT, wordness) \
  780. /* translations */ \
  781. X(INT, NONE, vtmode) \
  782. X(STR, NONE, line_codepage) \
  783. X(INT, NONE, cjk_ambig_wide) \
  784. X(INT, NONE, utf8_override) \
  785. X(INT, NONE, xlat_capslockcyr) \
  786. /* X11 forwarding */ \
  787. X(INT, NONE, x11_forward) \
  788. X(STR, NONE, x11_display) \
  789. X(INT, NONE, x11_auth) \
  790. X(FILENAME, NONE, xauthfile) \
  791. /* port forwarding */ \
  792. X(INT, NONE, lport_acceptall) /* accept conns from hosts other than localhost */ \
  793. X(INT, NONE, rport_acceptall) /* same for remote forwarded ports (SSH-2 only) */ \
  794. /* \
  795. * Subkeys for 'portfwd' can have the following forms: \
  796. * \
  797. * [LR]localport \
  798. * [LR]localaddr:localport \
  799. * \
  800. * Dynamic forwardings are indicated by an 'L' key, and the \
  801. * special value "D". For all other forwardings, the value \
  802. * should be of the form 'host:port'. \
  803. */ \
  804. X(STR, STR, portfwd) \
  805. /* SSH bug compatibility modes */ \
  806. X(INT, NONE, sshbug_ignore1) \
  807. X(INT, NONE, sshbug_plainpw1) \
  808. X(INT, NONE, sshbug_rsa1) \
  809. X(INT, NONE, sshbug_hmac2) \
  810. X(INT, NONE, sshbug_derivekey2) \
  811. X(INT, NONE, sshbug_rsapad2) \
  812. X(INT, NONE, sshbug_pksessid2) \
  813. X(INT, NONE, sshbug_rekey2) \
  814. X(INT, NONE, sshbug_maxpkt2) \
  815. X(INT, NONE, sshbug_ignore2) \
  816. X(INT, NONE, sshbug_oldgex2) \
  817. X(INT, NONE, sshbug_winadj) \
  818. X(INT, NONE, sshbug_chanreq) \
  819. /* \
  820. * ssh_simple means that we promise never to open any channel \
  821. * other than the main one, which means it can safely use a very \
  822. * large window in SSH-2. \
  823. */ \
  824. X(INT, NONE, ssh_simple) \
  825. X(INT, NONE, ssh_connection_sharing) \
  826. X(INT, NONE, ssh_connection_sharing_upstream) \
  827. X(INT, NONE, ssh_connection_sharing_downstream) \
  828. /*
  829. * ssh_manual_hostkeys is conceptually a set rather than a
  830. * dictionary: the string subkeys are the important thing, and the
  831. * actual values to which those subkeys map are all "".
  832. */ \
  833. X(STR, STR, ssh_manual_hostkeys) \
  834. /* Options for pterm. Should split out into platform-dependent part. */ \
  835. X(INT, NONE, stamp_utmp) \
  836. X(INT, NONE, login_shell) \
  837. X(INT, NONE, scrollbar_on_left) \
  838. X(INT, NONE, shadowbold) \
  839. X(FONT, NONE, boldfont) \
  840. X(FONT, NONE, widefont) \
  841. X(FONT, NONE, wideboldfont) \
  842. X(INT, NONE, shadowboldoffset) \
  843. X(INT, NONE, crhaslf) \
  844. X(STR, NONE, winclass) \
  845. /* Now define the actual enum of option keywords using that macro. */
  846. #define CONF_ENUM_DEF(valtype, keytype, keyword) CONF_ ## keyword,
  847. enum config_primary_key { CONFIG_OPTIONS(CONF_ENUM_DEF) N_CONFIG_OPTIONS };
  848. #undef CONF_ENUM_DEF
  849. #define NCFGCOLOURS 22 /* number of colours in CONF_colours above */
  850. /* Functions handling configuration structures. */
  851. Conf *conf_new(void); /* create an empty configuration */
  852. void conf_free(Conf *conf);
  853. Conf *conf_copy(Conf *oldconf);
  854. void conf_copy_into(Conf *dest, Conf *src);
  855. /* Mandatory accessor functions: enforce by assertion that keys exist. */
  856. int conf_get_int(Conf *conf, int key);
  857. int conf_get_int_int(Conf *conf, int key, int subkey);
  858. char *conf_get_str(Conf *conf, int key); /* result still owned by conf */
  859. char *conf_get_str_str(Conf *conf, int key, const char *subkey);
  860. Filename *conf_get_filename(Conf *conf, int key);
  861. FontSpec *conf_get_fontspec(Conf *conf, int key); /* still owned by conf */
  862. /* Optional accessor function: return NULL if key does not exist. */
  863. char *conf_get_str_str_opt(Conf *conf, int key, const char *subkey);
  864. /* Accessor function to step through a string-subkeyed list.
  865. * Returns the next subkey after the provided one, or the first if NULL.
  866. * Returns NULL if there are none left.
  867. * Both the return value and *subkeyout are still owned by conf. */
  868. char *conf_get_str_strs(Conf *conf, int key, char *subkeyin, char **subkeyout);
  869. /* Return the nth string subkey in a list. Owned by conf. NULL if beyond end */
  870. char *conf_get_str_nthstrkey(Conf *conf, int key, int n);
  871. /* Functions to set entries in configuration. Always copy their inputs. */
  872. void conf_set_int(Conf *conf, int key, int value);
  873. void conf_set_int_int(Conf *conf, int key, int subkey, int value);
  874. void conf_set_str(Conf *conf, int key, const char *value);
  875. void conf_set_str_str(Conf *conf, int key,
  876. const char *subkey, const char *val);
  877. void conf_del_str_str(Conf *conf, int key, const char *subkey);
  878. void conf_set_filename(Conf *conf, int key, const Filename *val);
  879. void conf_set_fontspec(Conf *conf, int key, const FontSpec *val);
  880. /* Serialisation functions for Duplicate Session */
  881. int conf_serialised_size(Conf *conf);
  882. void conf_serialise(Conf *conf, void *data);
  883. int conf_deserialise(Conf *conf, void *data, int maxsize);/*returns size used*/
  884. /*
  885. * Functions to copy, free, serialise and deserialise FontSpecs.
  886. * Provided per-platform, to go with the platform's idea of a
  887. * FontSpec's contents.
  888. *
  889. * fontspec_serialise returns the number of bytes written, and can
  890. * handle data==NULL without crashing. So you can call it once to find
  891. * out a size, then again once you've allocated a buffer.
  892. */
  893. FontSpec *fontspec_copy(const FontSpec *f);
  894. void fontspec_free(FontSpec *f);
  895. int fontspec_serialise(FontSpec *f, void *data);
  896. FontSpec *fontspec_deserialise(void *data, int maxsize, int *used);
  897. /*
  898. * Exports from noise.c.
  899. */
  900. void noise_get_heavy(void (*func) (void *, int));
  901. void noise_get_light(void (*func) (void *, int));
  902. void noise_regular(void);
  903. void noise_ultralight(unsigned long data);
  904. void random_save_seed(void);
  905. void random_destroy_seed(void);
  906. /*
  907. * Exports from settings.c.
  908. */
  909. Backend *backend_from_name(const char *name);
  910. Backend *backend_from_proto(int proto);
  911. char *get_remote_username(Conf *conf); /* dynamically allocated */
  912. char *save_settings(const char *section, Conf *conf);
  913. void save_open_settings(void *sesskey, Conf *conf);
  914. void load_settings(const char *section, Conf *conf);
  915. void load_open_settings(void *sesskey, Conf *conf);
  916. void get_sesslist(struct sesslist *, int allocate);
  917. void do_defaults(const char *, Conf *);
  918. void registry_cleanup(void);
  919. /*
  920. * Functions used by settings.c to provide platform-specific
  921. * default settings.
  922. *
  923. * (The integer one is expected to return `def' if it has no clear
  924. * opinion of its own. This is because there's no integer value
  925. * which I can reliably set aside to indicate `nil'. The string
  926. * function is perfectly all right returning NULL, of course. The
  927. * Filename and FontSpec functions are _not allowed_ to fail to
  928. * return, since these defaults _must_ be per-platform.)
  929. *
  930. * The 'Filename *' returned by platform_default_filename, and the
  931. * 'FontSpec *' returned by platform_default_fontspec, have ownership
  932. * transferred to the caller, and must be freed.
  933. */
  934. char *platform_default_s(const char *name);
  935. int platform_default_i(const char *name, int def);
  936. Filename *platform_default_filename(const char *name);
  937. FontSpec *platform_default_fontspec(const char *name);
  938. /*
  939. * Exports from terminal.c.
  940. */
  941. Terminal *term_init(Conf *, struct unicode_data *, void *);
  942. void term_free(Terminal *);
  943. void term_size(Terminal *, int, int, int);
  944. void term_paint(Terminal *, Context, int, int, int, int, int);
  945. void term_scroll(Terminal *, int, int);
  946. void term_scroll_to_selection(Terminal *, int);
  947. void term_pwron(Terminal *, int);
  948. void term_clrsb(Terminal *);
  949. void term_mouse(Terminal *, Mouse_Button, Mouse_Button, Mouse_Action,
  950. int,int,int,int,int);
  951. void term_key(Terminal *, Key_Sym, wchar_t *, size_t, unsigned int,
  952. unsigned int);
  953. void term_deselect(Terminal *);
  954. void term_update(Terminal *);
  955. void term_invalidate(Terminal *);
  956. void term_blink(Terminal *, int set_cursor);
  957. void term_do_paste(Terminal *);
  958. void term_nopaste(Terminal *);
  959. int term_ldisc(Terminal *, int option);
  960. void term_copyall(Terminal *);
  961. void term_reconfig(Terminal *, Conf *);
  962. void term_seen_key_event(Terminal *);
  963. int term_data(Terminal *, int is_stderr, const char *data, int len);
  964. int term_data_untrusted(Terminal *, const char *data, int len);
  965. void term_provide_resize_fn(Terminal *term,
  966. void (*resize_fn)(void *, int, int),
  967. void *resize_ctx);
  968. void term_provide_logctx(Terminal *term, void *logctx);
  969. void term_set_focus(Terminal *term, int has_focus);
  970. char *term_get_ttymode(Terminal *term, const char *mode);
  971. int term_get_userpass_input(Terminal *term, prompts_t *p,
  972. const unsigned char *in, int inlen);
  973. int format_arrow_key(char *buf, Terminal *term, int xkey, int ctrl);
  974. /*
  975. * Exports from logging.c.
  976. */
  977. void *log_init(void *frontend, Conf *conf);
  978. void log_free(void *logctx);
  979. void log_reconfig(void *logctx, Conf *conf);
  980. void logfopen(void *logctx);
  981. void logfclose(void *logctx);
  982. void logtraffic(void *logctx, unsigned char c, int logmode);
  983. void logflush(void *logctx);
  984. void log_eventlog(void *logctx, const char *string);
  985. enum { PKT_INCOMING, PKT_OUTGOING };
  986. enum { PKTLOG_EMIT, PKTLOG_BLANK, PKTLOG_OMIT };
  987. struct logblank_t {
  988. int offset;
  989. int len;
  990. int type;
  991. };
  992. void log_packet(void *logctx, int direction, int type,
  993. const char *texttype, const void *data, int len,
  994. int n_blanks, const struct logblank_t *blanks,
  995. const unsigned long *sequence,
  996. unsigned downstream_id, const char *additional_log_text);
  997. /*
  998. * Exports from testback.c
  999. */
  1000. extern Backend null_backend;
  1001. extern Backend loop_backend;
  1002. /*
  1003. * Exports from raw.c.
  1004. */
  1005. extern Backend raw_backend;
  1006. /*
  1007. * Exports from rlogin.c.
  1008. */
  1009. extern Backend rlogin_backend;
  1010. /*
  1011. * Exports from telnet.c.
  1012. */
  1013. extern Backend telnet_backend;
  1014. /*
  1015. * Exports from ssh.c.
  1016. */
  1017. extern Backend ssh_backend;
  1018. /*
  1019. * Exports from ldisc.c.
  1020. */
  1021. void *ldisc_create(Conf *, Terminal *, Backend *, void *, void *);
  1022. void ldisc_configure(void *, Conf *);
  1023. void ldisc_free(void *);
  1024. void ldisc_send(void *handle, const char *buf, int len, int interactive);
  1025. void ldisc_echoedit_update(void *handle);
  1026. /*
  1027. * Exports from ldiscucs.c.
  1028. */
  1029. void lpage_send(void *, int codepage, const char *buf, int len,
  1030. int interactive);
  1031. void luni_send(void *, const wchar_t * widebuf, int len, int interactive);
  1032. /*
  1033. * Exports from sshrand.c.
  1034. */
  1035. void random_add_noise(void *noise, int length);
  1036. int random_byte(void);
  1037. void random_get_savedata(void **data, int *len);
  1038. extern int random_active;
  1039. /* The random number subsystem is activated if at least one other entity
  1040. * within the program expresses an interest in it. So each SSH session
  1041. * calls random_ref on startup and random_unref on shutdown. */
  1042. void random_ref(void);
  1043. void random_unref(void);
  1044. /*
  1045. * Exports from pinger.c.
  1046. */
  1047. typedef struct pinger_tag *Pinger;
  1048. Pinger pinger_new(Conf *conf, Backend *back, void *backhandle);
  1049. void pinger_reconfig(Pinger, Conf *oldconf, Conf *newconf);
  1050. void pinger_free(Pinger);
  1051. /*
  1052. * Exports from misc.c.
  1053. */
  1054. #include "misc.h"
  1055. int conf_launchable(Conf *conf);
  1056. char const *conf_dest(Conf *conf);
  1057. /*
  1058. * Exports from sercfg.c.
  1059. */
  1060. void ser_setup_config_box(struct controlbox *b, int midsession,
  1061. int parity_mask, int flow_mask);
  1062. /*
  1063. * Exports from version.c.
  1064. */
  1065. extern const char ver[];
  1066. /*
  1067. * Exports from unicode.c.
  1068. */
  1069. #ifndef CP_UTF8
  1070. #define CP_UTF8 65001
  1071. #endif
  1072. /* void init_ucs(void); -- this is now in platform-specific headers */
  1073. int is_dbcs_leadbyte(int codepage, char byte);
  1074. int mb_to_wc(int codepage, int flags, const char *mbstr, int mblen,
  1075. wchar_t *wcstr, int wclen);
  1076. int wc_to_mb(int codepage, int flags, const wchar_t *wcstr, int wclen,
  1077. char *mbstr, int mblen, const char *defchr, int *defused,
  1078. struct unicode_data *ucsdata);
  1079. wchar_t xlat_uskbd2cyrllic(int ch);
  1080. int check_compose(int first, int second);
  1081. int decode_codepage(char *cp_name);
  1082. const char *cp_enumerate (int index);
  1083. const char *cp_name(int codepage);
  1084. void get_unitab(int codepage, wchar_t * unitab, int ftype);
  1085. /*
  1086. * Exports from wcwidth.c
  1087. */
  1088. int mk_wcwidth(unsigned int ucs);
  1089. int mk_wcswidth(const unsigned int *pwcs, size_t n);
  1090. int mk_wcwidth_cjk(unsigned int ucs);
  1091. int mk_wcswidth_cjk(const unsigned int *pwcs, size_t n);
  1092. /*
  1093. * Exports from mscrypto.c
  1094. */
  1095. #ifdef MSCRYPTOAPI
  1096. int crypto_startup();
  1097. void crypto_wrapup();
  1098. #endif
  1099. /*
  1100. * Exports from pageantc.c.
  1101. *
  1102. * agent_query returns 1 for here's-a-response, and 0 for query-in-
  1103. * progress. In the latter case there will be a call to `callback'
  1104. * at some future point, passing callback_ctx as the first
  1105. * parameter and the actual reply data as the second and third.
  1106. *
  1107. * The response may be a NULL pointer (in either of the synchronous
  1108. * or asynchronous cases), which indicates failure to receive a
  1109. * response.
  1110. */
  1111. int agent_query(void *in, int inlen, void **out, int *outlen,
  1112. void (*callback)(void *, void *, int), void *callback_ctx);
  1113. int agent_exists(void);
  1114. /*
  1115. * Exports from wildcard.c
  1116. */
  1117. const char *wc_error(int value);
  1118. int wc_match(const char *wildcard, const char *target);
  1119. int wc_unescape(char *output, const char *wildcard);
  1120. /*
  1121. * Exports from frontend (windlg.c etc)
  1122. */
  1123. void logevent(void *frontend, const char *);
  1124. void pgp_fingerprints(void);
  1125. /*
  1126. * verify_ssh_host_key() can return one of three values:
  1127. *
  1128. * - +1 means `key was OK' (either already known or the user just
  1129. * approved it) `so continue with the connection'
  1130. *
  1131. * - 0 means `key was not OK, abandon the connection'
  1132. *
  1133. * - -1 means `I've initiated enquiries, please wait to be called
  1134. * back via the provided function with a result that's either 0
  1135. * or +1'.
  1136. */
  1137. int verify_ssh_host_key(void *frontend, char *host, int port,
  1138. const char *keytype, char *keystr, char *fingerprint,
  1139. void (*callback)(void *ctx, int result), void *ctx);
  1140. /*
  1141. * have_ssh_host_key() just returns true if a key of that type is
  1142. * already cached and false otherwise.
  1143. */
  1144. int have_ssh_host_key(const char *host, int port, const char *keytype);
  1145. /*
  1146. * askalg and askhk have the same set of return values as
  1147. * verify_ssh_host_key.
  1148. *
  1149. * (askhk is used in the case where we're using a host key below the
  1150. * warning threshold because that's all we have cached, but at least
  1151. * one acceptable algorithm is available that we don't have cached.)
  1152. */
  1153. int askalg(void *frontend, const char *algtype, const char *algname,
  1154. void (*callback)(void *ctx, int result), void *ctx);
  1155. int askhk(void *frontend, const char *algname, const char *betteralgs,
  1156. void (*callback)(void *ctx, int result), void *ctx);
  1157. /*
  1158. * askappend can return four values:
  1159. *
  1160. * - 2 means overwrite the log file
  1161. * - 1 means append to the log file
  1162. * - 0 means cancel logging for this session
  1163. * - -1 means please wait.
  1164. */
  1165. int askappend(void *frontend, Filename *filename,
  1166. void (*callback)(void *ctx, int result), void *ctx);
  1167. /*
  1168. * Exports from console frontends (wincons.c, uxcons.c)
  1169. * that aren't equivalents to things in windlg.c et al.
  1170. */
  1171. extern int console_batch_mode;
  1172. int console_get_userpass_input(prompts_t *p, const unsigned char *in,
  1173. int inlen);
  1174. void console_provide_logctx(void *logctx);
  1175. int is_interactive(void);
  1176. /*
  1177. * Exports from printing.c.
  1178. */
  1179. typedef struct printer_enum_tag printer_enum;
  1180. typedef struct printer_job_tag printer_job;
  1181. printer_enum *printer_start_enum(int *nprinters);
  1182. char *printer_get_name(printer_enum *, int);
  1183. void printer_finish_enum(printer_enum *);
  1184. printer_job *printer_start_job(char *printer);
  1185. void printer_job_data(printer_job *, void *, int);
  1186. void printer_finish_job(printer_job *);
  1187. /*
  1188. * Exports from cmdline.c (and also cmdline_error(), which is
  1189. * defined differently in various places and required _by_
  1190. * cmdline.c).
  1191. *
  1192. * Note that cmdline_process_param takes a const option string, but a
  1193. * writable argument string. That's not a mistake - that's so it can
  1194. * zero out password arguments in the hope of not having them show up
  1195. * avoidably in Unix 'ps'.
  1196. */
  1197. int cmdline_process_param(const char *, char *, int, Conf *);
  1198. void cmdline_run_saved(Conf *);
  1199. void cmdline_cleanup(void);
  1200. int cmdline_get_passwd_input(prompts_t *p, const unsigned char *in, int inlen);
  1201. #define TOOLTYPE_FILETRANSFER 1
  1202. #define TOOLTYPE_NONNETWORK 2
  1203. extern int cmdline_tooltype;
  1204. void cmdline_error(const char *, ...);
  1205. /*
  1206. * Exports from config.c.
  1207. */
  1208. struct controlbox;
  1209. union control;
  1210. void conf_radiobutton_handler(union control *ctrl, void *dlg,
  1211. void *data, int event);
  1212. #define CHECKBOX_INVERT (1<<30)
  1213. void conf_checkbox_handler(union control *ctrl, void *dlg,
  1214. void *data, int event);
  1215. void conf_editbox_handler(union control *ctrl, void *dlg,
  1216. void *data, int event);
  1217. void conf_filesel_handler(union control *ctrl, void *dlg,
  1218. void *data, int event);
  1219. void conf_fontsel_handler(union control *ctrl, void *dlg,
  1220. void *data, int event);
  1221. void setup_config_box(struct controlbox *b, int midsession,
  1222. int protocol, int protcfginfo);
  1223. /*
  1224. * Exports from minibidi.c.
  1225. */
  1226. typedef struct bidi_char {
  1227. unsigned int origwc, wc;
  1228. unsigned short index;
  1229. } bidi_char;
  1230. int do_bidi(bidi_char *line, int count);
  1231. int do_shape(bidi_char *line, bidi_char *to, int count);
  1232. int is_rtl(int c);
  1233. /*
  1234. * X11 auth mechanisms we know about.
  1235. */
  1236. enum {
  1237. X11_NO_AUTH,
  1238. X11_MIT, /* MIT-MAGIC-COOKIE-1 */
  1239. X11_XDM, /* XDM-AUTHORIZATION-1 */
  1240. X11_NAUTHS
  1241. };
  1242. extern const char *const x11_authnames[]; /* declared in x11fwd.c */
  1243. /*
  1244. * Miscellaneous exports from the platform-specific code.
  1245. *
  1246. * filename_serialise and filename_deserialise have the same semantics
  1247. * as fontspec_serialise and fontspec_deserialise above.
  1248. */
  1249. Filename *filename_from_str(const char *string);
  1250. const char *filename_to_str(const Filename *fn);
  1251. int filename_equal(const Filename *f1, const Filename *f2);
  1252. int filename_is_null(const Filename *fn);
  1253. Filename *filename_copy(const Filename *fn);
  1254. void filename_free(Filename *fn);
  1255. int filename_serialise(const Filename *f, void *data);
  1256. Filename *filename_deserialise(void *data, int maxsize, int *used);
  1257. char *get_username(void); /* return value needs freeing */
  1258. char *get_random_data(int bytes, const char *device); /* used in cmdgen.c */
  1259. char filename_char_sanitise(char c); /* rewrite special pathname chars */
  1260. /*
  1261. * Exports and imports from timing.c.
  1262. *
  1263. * schedule_timer() asks the front end to schedule a callback to a
  1264. * timer function in a given number of ticks. The returned value is
  1265. * the time (in ticks since an arbitrary offset) at which the
  1266. * callback can be expected. This value will also be passed as the
  1267. * `now' parameter to the callback function. Hence, you can (for
  1268. * example) schedule an event at a particular time by calling
  1269. * schedule_timer() and storing the return value in your context
  1270. * structure as the time when that event is due. The first time a
  1271. * callback function gives you that value or more as `now', you do
  1272. * the thing.
  1273. *
  1274. * expire_timer_context() drops all current timers associated with
  1275. * a given value of ctx (for when you're about to free ctx).
  1276. *
  1277. * run_timers() is called from the front end when it has reason to
  1278. * think some timers have reached their moment, or when it simply
  1279. * needs to know how long to wait next. We pass it the time we
  1280. * think it is. It returns TRUE and places the time when the next
  1281. * timer needs to go off in `next', or alternatively it returns
  1282. * FALSE if there are no timers at all pending.
  1283. *
  1284. * timer_change_notify() must be supplied by the front end; it
  1285. * notifies the front end that a new timer has been added to the
  1286. * list which is sooner than any existing ones. It provides the
  1287. * time when that timer needs to go off.
  1288. *
  1289. * *** FRONT END IMPLEMENTORS NOTE:
  1290. *
  1291. * There's an important subtlety in the front-end implementation of
  1292. * the timer interface. When a front end is given a `next' value,
  1293. * either returned from run_timers() or via timer_change_notify(),
  1294. * it should ensure that it really passes _that value_ as the `now'
  1295. * parameter to its next run_timers call. It should _not_ simply
  1296. * call GETTICKCOUNT() to get the `now' parameter when invoking
  1297. * run_timers().
  1298. *
  1299. * The reason for this is that an OS's system clock might not agree
  1300. * exactly with the timing mechanisms it supplies to wait for a
  1301. * given interval. I'll illustrate this by the simple example of
  1302. * Unix Plink, which uses timeouts to select() in a way which for
  1303. * these purposes can simply be considered to be a wait() function.
  1304. * Suppose, for the sake of argument, that this wait() function
  1305. * tends to return early by 1%. Then a possible sequence of actions
  1306. * is:
  1307. *
  1308. * - run_timers() tells the front end that the next timer firing
  1309. * is 10000ms from now.
  1310. * - Front end calls wait(10000ms), but according to
  1311. * GETTICKCOUNT() it has only waited for 9900ms.
  1312. * - Front end calls run_timers() again, passing time T-100ms as
  1313. * `now'.
  1314. * - run_timers() does nothing, and says the next timer firing is
  1315. * still 100ms from now.
  1316. * - Front end calls wait(100ms), which only waits for 99ms.
  1317. * - Front end calls run_timers() yet again, passing time T-1ms.
  1318. * - run_timers() says there's still 1ms to wait.
  1319. * - Front end calls wait(1ms).
  1320. *
  1321. * If you're _lucky_ at this point, wait(1ms) will actually wait
  1322. * for 1ms and you'll only have woken the program up three times.
  1323. * If you're unlucky, wait(1ms) might do nothing at all due to
  1324. * being below some minimum threshold, and you might find your
  1325. * program spends the whole of the last millisecond tight-looping
  1326. * between wait() and run_timers().
  1327. *
  1328. * Instead, what you should do is to _save_ the precise `next'
  1329. * value provided by run_timers() or via timer_change_notify(), and
  1330. * use that precise value as the input to the next run_timers()
  1331. * call. So:
  1332. *
  1333. * - run_timers() tells the front end that the next timer firing
  1334. * is at time T, 10000ms from now.
  1335. * - Front end calls wait(10000ms).
  1336. * - Front end then immediately calls run_timers() and passes it
  1337. * time T, without stopping to check GETTICKCOUNT() at all.
  1338. *
  1339. * This guarantees that the program wakes up only as many times as
  1340. * there are actual timer actions to be taken, and that the timing
  1341. * mechanism will never send it into a tight loop.
  1342. *
  1343. * (It does also mean that the timer action in the above example
  1344. * will occur 100ms early, but this is not generally critical. And
  1345. * the hypothetical 1% error in wait() will be partially corrected
  1346. * for anyway when, _after_ run_timers() returns, you call
  1347. * GETTICKCOUNT() and compare the result with the returned `next'
  1348. * value to find out how long you have to make your next wait().)
  1349. */
  1350. typedef void (*timer_fn_t)(void *ctx, unsigned long now);
  1351. unsigned long schedule_timer(int ticks, timer_fn_t fn, void *ctx);
  1352. void expire_timer_context(void *ctx);
  1353. int run_timers(unsigned long now, unsigned long *next);
  1354. void timer_change_notify(unsigned long next);
  1355. unsigned long timing_last_clock(void);
  1356. /*
  1357. * Exports from callback.c.
  1358. *
  1359. * This provides a method of queuing function calls to be run at the
  1360. * earliest convenience from the top-level event loop. Use it if
  1361. * you're deep in a nested chain of calls and want to trigger an
  1362. * action which will probably lead to your function being re-entered
  1363. * recursively if you just call the initiating function the normal
  1364. * way.
  1365. *
  1366. * Most front ends run the queued callbacks by simply calling
  1367. * run_toplevel_callbacks() after handling each event in their
  1368. * top-level event loop. However, if a front end doesn't have control
  1369. * over its own event loop (e.g. because it's using GTK) then it can
  1370. * instead request notifications when a callback is available, so that
  1371. * it knows to ask its delegate event loop to do the same thing. Also,
  1372. * if a front end needs to know whether a callback is pending without
  1373. * actually running it (e.g. so as to put a zero timeout on a select()
  1374. * call) then it can call toplevel_callback_pending(), which will
  1375. * return true if at least one callback is in the queue.
  1376. */
  1377. typedef void (*toplevel_callback_fn_t)(void *ctx);
  1378. void queue_toplevel_callback(toplevel_callback_fn_t fn, void *ctx);
  1379. void run_toplevel_callbacks(void);
  1380. int toplevel_callback_pending(void);
  1381. typedef void (*toplevel_callback_notify_fn_t)(void *frontend);
  1382. void request_callback_notifications(toplevel_callback_notify_fn_t notify,
  1383. void *frontend);
  1384. /*
  1385. * Define no-op macros for the jump list functions, on platforms that
  1386. * don't support them. (This is a bit of a hack, and it'd be nicer to
  1387. * localise even the calls to those functions into the Windows front
  1388. * end, but it'll do for the moment.)
  1389. */
  1390. #ifndef JUMPLIST_SUPPORTED
  1391. #define add_session_to_jumplist(x) ((void)0)
  1392. #define remove_session_from_jumplist(x) ((void)0)
  1393. #endif
  1394. /* SURROGATE PAIR */
  1395. #define HIGH_SURROGATE_START 0xd800
  1396. #define HIGH_SURROGATE_END 0xdbff
  1397. #define LOW_SURROGATE_START 0xdc00
  1398. #define LOW_SURROGATE_END 0xdfff
  1399. /* These macros exist in the Windows API, so the environment may
  1400. * provide them. If not, define them in terms of the above. */
  1401. #ifndef IS_HIGH_SURROGATE
  1402. #define IS_HIGH_SURROGATE(wch) (((wch) >= HIGH_SURROGATE_START) && \
  1403. ((wch) <= HIGH_SURROGATE_END))
  1404. #define IS_LOW_SURROGATE(wch) (((wch) >= LOW_SURROGATE_START) && \
  1405. ((wch) <= LOW_SURROGATE_END))
  1406. #define IS_SURROGATE_PAIR(hs, ls) (IS_HIGH_SURROGATE(hs) && \
  1407. IS_LOW_SURROGATE(ls))
  1408. #endif
  1409. #define IS_SURROGATE(wch) (((wch) >= HIGH_SURROGATE_START) && \
  1410. ((wch) <= LOW_SURROGATE_END))
  1411. #define HIGH_SURROGATE_OF(codept) \
  1412. (HIGH_SURROGATE_START + (((codept) - 0x10000) >> 10))
  1413. #define LOW_SURROGATE_OF(codept) \
  1414. (LOW_SURROGATE_START + (((codept) - 0x10000) & 0x3FF))
  1415. #define FROM_SURROGATES(wch1, wch2) \
  1416. (0x10000 + (((wch1) & 0x3FF) << 10) + ((wch2) & 0x3FF))
  1417. #endif