From 6561c7de35dcc4f5e2a206941c88ee2c6f0f46ab Mon Sep 17 00:00:00 2001 From: cyd01 Date: Wed, 6 Nov 2019 12:10:05 +0100 Subject: [PATCH] Tagging the 0.73.0.2 release of the kitty project. --- 0.72_My_PuTTY/windows/version_major.txt | 1 - 0.72_My_PuTTY/windows/version_minor.txt | 1 - {0.72_My_PuTTY => 0.73_My_PuTTY}/agentf.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/aqsync.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/be_all.c | 2 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/be_all_s.c | 6 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/be_misc.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/be_none.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/be_nos_s.c | 4 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/be_nossh.c | 4 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/be_ssh.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/callback.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/cgtest.c | 0 .../charset/charset.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/cmdgen.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/cmdline.c | 14 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/conf.c | 8 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/config.c | 157 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/cproxy.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/defs.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/dialog.c | 4 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/dialog.h | 10 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/ecc.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/ecc.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/empty.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/errsock.c | 1 - {0.72_My_PuTTY => 0.73_My_PuTTY}/fuzzterm.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/import.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/ldisc.c | 6 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/ldisc.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/licence.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/logging.c | 12 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/mainchan.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/marshal.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/marshal.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/memory.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/minibidi.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/misc.c | 4 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/misc.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/miscucs.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/mpint.c | 4790 ++++++++--------- {0.72_My_PuTTY => 0.73_My_PuTTY}/mpint.h | 806 +-- {0.72_My_PuTTY => 0.73_My_PuTTY}/mpint_i.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/network.h | 7 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/nocmdline.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/nocproxy.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/nogss.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/noprint.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/noshare.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/noterm.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/notiming.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/nullplug.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/pageant.c | 18 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/pageant.h | 2 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/pgssapi.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/pgssapi.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/pinger.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/portfwd.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/pproxy.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/proxy.c | 20 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/proxy.h | 1 - {0.72_My_PuTTY => 0.73_My_PuTTY}/pscp.c | 18 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/psftp.c | 16 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/psftp.h | 0 .../psftpcommon.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/putty.h | 52 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/puttymem.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/puttyps.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/raw.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/resource.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/rlogin.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/scpserver.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sercfg.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sesschan.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sessprep.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/settings.c | 80 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/sftp.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sftp.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sftpcommon.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sftpserver.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh.c | 3 + {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh.h | 2 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh1bpp.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh1censor.c | 0 .../ssh1connection-client.c | 0 .../ssh1connection-server.c | 0 .../ssh1connection.c | 1688 +++--- .../ssh1connection.h | 0 .../ssh1login-server.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh1login.c | 4 +- .../ssh2bpp-bare.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh2bpp.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh2censor.c | 0 .../ssh2connection-client.c | 0 .../ssh2connection-server.c | 0 .../ssh2connection.c | 3492 ++++++------ .../ssh2connection.h | 0 .../ssh2kex-client.c | 0 .../ssh2kex-server.c | 0 .../ssh2transhk.c | 0 .../ssh2transport.c | 3 +- .../ssh2transport.h | 0 .../ssh2userauth-server.c | 0 .../ssh2userauth.c | 42 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/sshaes.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/ssharcf.c | 0 .../sshauxcrypt.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshbcrypt.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshblowf.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshblowf.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshbpp.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshccp.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshchan.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshcommon.c | 2 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/sshcr.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshcrc.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshcrcda.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshdes.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshdh.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshdss.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshdssg.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshecc.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshecdsag.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshgss.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshgssc.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshgssc.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshhmac.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshmac.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshmd5.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshnogss.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshppl.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshprime.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshprng.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshpubk.c | 8 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/sshrand.c | 4 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/sshrsa.c | 4 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/sshrsag.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshserver.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshserver.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshsh256.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshsh512.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshsha.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshshare.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/sshsignals.h | 0 .../sshttymodes.h | 0 .../sshverstring.c | 2 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/sshzlib.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/storage.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/stripctrl.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/telnet.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/terminal.c | 101 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/terminal.h | 7 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/testback.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/testcrypt.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/testcrypt.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/testsc.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/testzlib.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/time.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/timing.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/tree234.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/tree234.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/unix/unix.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/utils.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/version.c | 2 +- {0.72_My_PuTTY => 0.73_My_PuTTY}/version.h | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/wcwidth.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/wildcard.c | 0 .../windows/MAKEFILE.MINGW | 110 +- .../windows/pageant.ico | Bin .../windows/pageant.rc | 12 +- .../windows/pageants.ico | Bin .../windows/plink.rc | 0 .../windows/pscp.ico | Bin .../windows/pscp.rc | 0 .../windows/psftp.rc | 0 .../windows/putty.ico | Bin .../windows/putty.mft | 0 .../windows/putty.rc | 0 .../windows/puttycfg.ico | Bin .../windows/puttygen.ico | Bin .../windows/puttygen.rc | 10 +- .../windows/puttyins.ico | Bin .../windows/puttytel.rc | 0 .../windows/rcstuff.h | 0 .../windows/sizetip.c | 0 .../windows/version.rc2 | 2 +- 0.73_My_PuTTY/windows/version_major.txt | 1 + 0.73_My_PuTTY/windows/version_minor.txt | 1 + .../windows/win_res.h | 4 +- .../windows/win_res.rc2 | 14 +- .../windows/wincapi.c | 0 .../windows/wincapi.h | 0 .../windows/wincfg.c | 24 +- .../windows/wincons.c | 6 +- .../windows/winctrls.c | 28 +- .../windows/windefs.c | 0 .../windows/windlg.c | 30 +- .../windows/window.c | 356 +- .../windows/wingss.c | 0 .../windows/winhandl.c | 0 .../windows/winhelp.c | 2 +- .../windows/winhelp.h | 0 .../windows/winhelp.rc2 | 0 .../windows/winhsock.c | 7 - .../windows/winjump.c | 2 +- .../windows/winmisc.c | 0 .../windows/winmiscs.c | 0 .../windows/winnet.c | 68 +- .../windows/winnohlp.c | 0 .../windows/winnoise.c | 0 .../windows/winnojmp.c | 0 .../windows/winnpc.c | 0 .../windows/winnps.c | 3 +- .../windows/winpgen.c | 14 +- .../windows/winpgnt.c | 36 +- .../windows/winpgntc.c | 0 .../windows/winplink.c | 60 +- .../windows/winprint.c | 0 .../windows/winproxy.c | 0 .../windows/winsecur.c | 0 .../windows/winsecur.h | 0 .../windows/winser.c | 0 .../windows/winsftp.c | 6 +- .../windows/winshare.c | 0 .../windows/winstore.c | 51 +- .../windows/winstuff.h | 8 +- .../windows/wintime.c | 0 .../windows/winucs.c | 0 .../windows/winutils.c | 0 .../windows/winx11.c | 0 {0.72_My_PuTTY => 0.73_My_PuTTY}/x11fwd.c | 0 adb/adb.c | 2 +- cygterm/cygcfg.c | 2 +- cygterm/cygterm.c | 2 +- kitty.c | 108 +- kitty.h | 18 +- kitty_commun.c | 12 +- kitty_commun.h | 4 +- kitty_image.c | 304 +- kitty_image.h | 2 +- kitty_launcher.c | 4 +- kitty_savedump.c | 36 +- kitty_settings.c | 66 +- kitty_ssh.c | 2 +- kitty_ssh.h | 2 +- kitty_win.c | 2 +- url/re_lib/regexp.c | 6 +- url/urlhack.c | 4 +- url/urlhack.old.c | 4 +- void.c | 2 +- wincrypt/wincrypto.c | 2 +- wincrypt/wincrypto.h | 2 +- zmodem/winpzmodem.c | 2 +- 253 files changed, 6395 insertions(+), 6456 deletions(-) delete mode 100644 0.72_My_PuTTY/windows/version_major.txt delete mode 100644 0.72_My_PuTTY/windows/version_minor.txt rename {0.72_My_PuTTY => 0.73_My_PuTTY}/agentf.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/aqsync.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/be_all.c (98%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/be_all_s.c (92%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/be_misc.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/be_none.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/be_nos_s.c (94%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/be_nossh.c (94%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/be_ssh.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/callback.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/cgtest.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/charset/charset.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/cmdgen.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/cmdline.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/conf.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/config.c (98%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/cproxy.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/defs.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/dialog.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/dialog.h (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ecc.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ecc.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/empty.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/errsock.c (98%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/fuzzterm.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/import.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ldisc.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ldisc.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/licence.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/logging.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/mainchan.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/marshal.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/marshal.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/memory.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/minibidi.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/misc.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/misc.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/miscucs.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/mpint.c (97%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/mpint.h (97%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/mpint_i.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/network.h (98%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/nocmdline.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/nocproxy.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/nogss.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/noprint.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/noshare.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/noterm.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/notiming.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/nullplug.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/pageant.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/pageant.h (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/pgssapi.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/pgssapi.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/pinger.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/portfwd.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/pproxy.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/proxy.c (98%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/proxy.h (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/pscp.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/psftp.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/psftp.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/psftpcommon.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/putty.h (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/puttymem.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/puttyps.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/raw.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/resource.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/rlogin.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/scpserver.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sercfg.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sesschan.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sessprep.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/settings.c (98%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sftp.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sftp.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sftpcommon.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sftpserver.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh.c (96%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh.h (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh1bpp.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh1censor.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh1connection-client.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh1connection-server.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh1connection.c (96%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh1connection.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh1login-server.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh1login.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh2bpp-bare.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh2bpp.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh2censor.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh2connection-client.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh2connection-server.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh2connection.c (97%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh2connection.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh2kex-client.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh2kex-server.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh2transhk.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh2transport.c (97%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh2transport.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh2userauth-server.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssh2userauth.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshaes.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/ssharcf.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshauxcrypt.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshbcrypt.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshblowf.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshblowf.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshbpp.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshccp.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshchan.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshcommon.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshcr.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshcrc.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshcrcda.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshdes.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshdh.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshdss.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshdssg.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshecc.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshecdsag.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshgss.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshgssc.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshgssc.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshhmac.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshmac.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshmd5.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshnogss.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshppl.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshprime.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshprng.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshpubk.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshrand.c (98%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshrsa.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshrsag.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshserver.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshserver.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshsh256.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshsh512.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshsha.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshshare.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshsignals.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshttymodes.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshverstring.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/sshzlib.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/storage.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/stripctrl.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/telnet.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/terminal.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/terminal.h (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/testback.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/testcrypt.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/testcrypt.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/testsc.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/testzlib.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/time.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/timing.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/tree234.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/tree234.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/unix/unix.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/utils.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/version.c (98%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/version.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/wcwidth.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/wildcard.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/MAKEFILE.MINGW (97%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/pageant.ico (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/pageant.rc (94%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/pageants.ico (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/plink.rc (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/pscp.ico (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/pscp.rc (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/psftp.rc (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/putty.ico (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/putty.mft (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/putty.rc (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/puttycfg.ico (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/puttygen.ico (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/puttygen.rc (93%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/puttyins.ico (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/puttytel.rc (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/rcstuff.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/sizetip.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/version.rc2 (98%) create mode 100644 0.73_My_PuTTY/windows/version_major.txt create mode 100644 0.73_My_PuTTY/windows/version_minor.txt rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/win_res.h (98%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/win_res.rc2 (97%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/wincapi.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/wincapi.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/wincfg.c (98%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/wincons.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winctrls.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/windefs.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/windlg.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/window.c (98%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/wingss.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winhandl.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winhelp.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winhelp.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winhelp.rc2 (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winhsock.c (98%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winjump.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winmisc.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winmiscs.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winnet.c (98%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winnohlp.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winnoise.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winnojmp.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winnpc.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winnps.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winpgen.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winpgnt.c (98%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winpgntc.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winplink.c (97%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winprint.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winproxy.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winsecur.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winsecur.h (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winser.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winsftp.c (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winshare.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winstore.c (98%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winstuff.h (99%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/wintime.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winucs.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winutils.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/windows/winx11.c (100%) rename {0.72_My_PuTTY => 0.73_My_PuTTY}/x11fwd.c (100%) diff --git a/0.72_My_PuTTY/windows/version_major.txt b/0.72_My_PuTTY/windows/version_major.txt deleted file mode 100644 index b851df7..0000000 --- a/0.72_My_PuTTY/windows/version_major.txt +++ /dev/null @@ -1 +0,0 @@ -"0.72.0" diff --git a/0.72_My_PuTTY/windows/version_minor.txt b/0.72_My_PuTTY/windows/version_minor.txt deleted file mode 100644 index 1e8b314..0000000 --- a/0.72_My_PuTTY/windows/version_minor.txt +++ /dev/null @@ -1 +0,0 @@ -6 diff --git a/0.72_My_PuTTY/agentf.c b/0.73_My_PuTTY/agentf.c similarity index 100% rename from 0.72_My_PuTTY/agentf.c rename to 0.73_My_PuTTY/agentf.c diff --git a/0.72_My_PuTTY/aqsync.c b/0.73_My_PuTTY/aqsync.c similarity index 100% rename from 0.72_My_PuTTY/aqsync.c rename to 0.73_My_PuTTY/aqsync.c diff --git a/0.72_My_PuTTY/be_all.c b/0.73_My_PuTTY/be_all.c similarity index 98% rename from 0.72_My_PuTTY/be_all.c rename to 0.73_My_PuTTY/be_all.c index cbb9193..1459c6a 100644 --- a/0.72_My_PuTTY/be_all.c +++ b/0.73_My_PuTTY/be_all.c @@ -27,7 +27,7 @@ const struct BackendVtable *const backends[] = { &telnet_backend, &rlogin_backend, &raw_backend, -#ifdef ADBPORT +#ifdef MOD_ADB &adb_backend, #endif NULL diff --git a/0.72_My_PuTTY/be_all_s.c b/0.73_My_PuTTY/be_all_s.c similarity index 92% rename from 0.72_My_PuTTY/be_all_s.c rename to 0.73_My_PuTTY/be_all_s.c index 0b1429e..1943c54 100644 --- a/0.72_My_PuTTY/be_all_s.c +++ b/0.73_My_PuTTY/be_all_s.c @@ -14,7 +14,7 @@ * have tiny little source modules containing nothing but * declarations of appname, for as long as I can... */ -#if (defined PERSOPORT) && (!defined FDJ) +#if (defined MOD_PERSO) && (!defined FDJ) char *appname = "KiTTY"; #else const char *const appname = "PuTTY"; @@ -32,10 +32,10 @@ const struct BackendVtable *const backends[] = { &rlogin_backend, &raw_backend, &serial_backend, -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM &cygterm_backend, #endif -#ifdef ADBPORT +#ifdef MOD_ADB &adb_backend, #endif NULL diff --git a/0.72_My_PuTTY/be_misc.c b/0.73_My_PuTTY/be_misc.c similarity index 100% rename from 0.72_My_PuTTY/be_misc.c rename to 0.73_My_PuTTY/be_misc.c diff --git a/0.72_My_PuTTY/be_none.c b/0.73_My_PuTTY/be_none.c similarity index 100% rename from 0.72_My_PuTTY/be_none.c rename to 0.73_My_PuTTY/be_none.c diff --git a/0.72_My_PuTTY/be_nos_s.c b/0.73_My_PuTTY/be_nos_s.c similarity index 94% rename from 0.72_My_PuTTY/be_nos_s.c rename to 0.73_My_PuTTY/be_nos_s.c index dd689b3..1cce987 100644 --- a/0.72_My_PuTTY/be_nos_s.c +++ b/0.73_My_PuTTY/be_nos_s.c @@ -14,11 +14,11 @@ const struct BackendVtable *const backends[] = { &telnet_backend, &rlogin_backend, &raw_backend, -#ifdef ADBPORT +#ifdef MOD_ADB &adb_backend, #endif &serial_backend, -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM &cygterm_backend, #endif NULL diff --git a/0.72_My_PuTTY/be_nossh.c b/0.73_My_PuTTY/be_nossh.c similarity index 94% rename from 0.72_My_PuTTY/be_nossh.c rename to 0.73_My_PuTTY/be_nossh.c index 1f23743..7d53b10 100644 --- a/0.72_My_PuTTY/be_nossh.c +++ b/0.73_My_PuTTY/be_nossh.c @@ -14,10 +14,10 @@ const struct BackendVtable *const backends[] = { &telnet_backend, &rlogin_backend, &raw_backend, -#ifdef ADBPORT +#ifdef MOD_ADB &adb_backend, #endif -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM &cygterm_backend, #endif NULL diff --git a/0.72_My_PuTTY/be_ssh.c b/0.73_My_PuTTY/be_ssh.c similarity index 100% rename from 0.72_My_PuTTY/be_ssh.c rename to 0.73_My_PuTTY/be_ssh.c diff --git a/0.72_My_PuTTY/callback.c b/0.73_My_PuTTY/callback.c similarity index 100% rename from 0.72_My_PuTTY/callback.c rename to 0.73_My_PuTTY/callback.c diff --git a/0.72_My_PuTTY/cgtest.c b/0.73_My_PuTTY/cgtest.c similarity index 100% rename from 0.72_My_PuTTY/cgtest.c rename to 0.73_My_PuTTY/cgtest.c diff --git a/0.72_My_PuTTY/charset/charset.h b/0.73_My_PuTTY/charset/charset.h similarity index 100% rename from 0.72_My_PuTTY/charset/charset.h rename to 0.73_My_PuTTY/charset/charset.h diff --git a/0.72_My_PuTTY/cmdgen.c b/0.73_My_PuTTY/cmdgen.c similarity index 100% rename from 0.72_My_PuTTY/cmdgen.c rename to 0.73_My_PuTTY/cmdgen.c diff --git a/0.72_My_PuTTY/cmdline.c b/0.73_My_PuTTY/cmdline.c similarity index 99% rename from 0.72_My_PuTTY/cmdline.c rename to 0.73_My_PuTTY/cmdline.c index f233985..da15eee 100644 --- a/0.72_My_PuTTY/cmdline.c +++ b/0.73_My_PuTTY/cmdline.c @@ -28,13 +28,13 @@ * executed immediately.) */ -#ifdef PERSOPORT +#ifdef MOD_PERSO #include "kitty_crypt.h" int decode64(char *buffer) ; void SetAutoStoreSSHKey( void ) ; void load_open_settings_forced(char *filename, Conf *conf) ; #endif -#ifdef ADBPORT +#ifdef MOD_ADB int GetADBFlag(void) ; #endif @@ -168,7 +168,7 @@ static bool cmdline_check_unavailable(int flag, const char *p) static bool seen_hostname_argument = false; static bool seen_port_argument = false; -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM void cygterm_set_flag( int flag ) ; bool get_got_host(void){ return seen_hostname_argument ; } void set_got_host(bool val ){ seen_hostname_argument = val ; } @@ -259,7 +259,7 @@ int cmdline_process_param(const char *p, char *value, } else { conf_set_int(conf, CONF_port, -1); } -#ifdef PERSOPORT +#ifdef MOD_PERSO } else if (!strncmp(p, "ssh:", 4)) { char *pst = (char*)malloc(strlen(p)+1) ; strcpy(pst,p); char *q = (char*)pst ; @@ -518,7 +518,7 @@ int cmdline_process_param(const char *p, char *value, default_protocol = PROT_RAW; conf_set_int(conf, CONF_protocol, default_protocol); } -#ifdef PERSOPORT +#ifdef MOD_PERSO if (!strcmp(p, "-kload")) { RETURN(2); /* This parameter must be processed immediately rather than being @@ -533,7 +533,7 @@ int cmdline_process_param(const char *p, char *value, SetAutoStoreSSHKey(); } #endif -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM if (!strcmp(p, "-cygterm")) { RETURN(1); UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK); @@ -544,7 +544,7 @@ int cmdline_process_param(const char *p, char *value, return 1; } #endif -#ifdef ADBPORT +#ifdef MOD_ADB if (!strcmp(p, "-adb") && GetADBFlag()) { RETURN(1); UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK); diff --git a/0.72_My_PuTTY/conf.c b/0.73_My_PuTTY/conf.c similarity index 99% rename from 0.72_My_PuTTY/conf.c rename to 0.73_My_PuTTY/conf.c index 4717dd4..c27187c 100644 --- a/0.72_My_PuTTY/conf.c +++ b/0.73_My_PuTTY/conf.c @@ -266,7 +266,7 @@ bool conf_get_bool(Conf *conf, int primary) { struct key key; struct conf_entry *entry; -#ifdef PERSOPORT +#ifdef MOD_PERSO if( valuetypes[primary] == TYPE_INT ) { int i = conf_get_int( conf, primary ) ; if( i==0 ) { return false ; } @@ -285,7 +285,7 @@ int conf_get_int(Conf *conf, int primary) { struct key key; struct conf_entry *entry; -#ifdef PERSOPORT +#ifdef MOD_PERSO if( valuetypes[primary] == TYPE_BOOL ) { return (conf_get_bool( conf, primary ) ? 1 : 0) ; } @@ -416,7 +416,7 @@ FontSpec *conf_get_fontspec(Conf *conf, int primary) void conf_set_bool(Conf *conf, int primary, bool value) { struct conf_entry *entry = snew(struct conf_entry); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( valuetypes[primary] == TYPE_INT ) { conf_set_int( conf, primary, (value?1:0) ); return ; @@ -432,7 +432,7 @@ void conf_set_bool(Conf *conf, int primary, bool value) void conf_set_int(Conf *conf, int primary, int value) { struct conf_entry *entry = snew(struct conf_entry); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( valuetypes[primary] == TYPE_BOOL ) { conf_set_bool( conf, primary, (value==0?false:true) ); return ; diff --git a/0.72_My_PuTTY/config.c b/0.73_My_PuTTY/config.c similarity index 98% rename from 0.72_My_PuTTY/config.c rename to 0.73_My_PuTTY/config.c index 44d319c..426b034 100644 --- a/0.72_My_PuTTY/config.c +++ b/0.73_My_PuTTY/config.c @@ -10,20 +10,20 @@ #include "dialog.h" #include "storage.h" -#ifdef RUTTYPORT +#ifdef MOD_RUTTY #include "script.h" #endif /* rutty */ -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM int cygterm_get_flag( void ) ; #endif -#ifdef PERSOPORT +#ifdef MOD_PERSO #include "kitty.h" union control * ctrlHostnameEdit = NULL ; void MASKPASS( char * password ) ; int stricmp(const char *s1, const char *s2) ; int GetReadOnlyFlag(void) ; #endif -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM #define ATOFFSET(data, offset) ( (void *) ( (char *)(data) + (offset) ) ) #endif @@ -185,7 +185,7 @@ void conf_filesel_handler(union control *ctrl, dlgparam *dlg, } } -#ifdef PERSOPORT +#ifdef MOD_PERSO void ReadAutoCommandFromFile( const char * filename ) ; void ReadInitScript( const char * filename ) ; int existfile( const char * filename ); @@ -239,7 +239,7 @@ static void config_host_handler(union control *ctrl, dlgparam *dlg, void *data, int event) { Conf *conf = (Conf *)data; -#ifdef PERSOPORT +#ifdef MOD_PERSO ctrlHostnameEdit = ctrl ; #endif @@ -256,12 +256,12 @@ static void config_host_handler(union control *ctrl, dlgparam *dlg, */ dlg_label_change(ctrl, dlg, "Serial line"); dlg_editbox_set(ctrl, dlg, conf_get_str(conf, CONF_serline)); -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM } else if( cygterm_get_flag() && (conf_get_int(conf, CONF_protocol) == PROT_CYGTERM) ) { dlg_label_change(ctrl, dlg, "Command (use - for login shell, ? for exe)"); dlg_editbox_set(ctrl, dlg, conf_get_str(conf, CONF_cygcmd) ); #endif -#ifdef ADBPORT +#ifdef MOD_ADB } else if (conf_get_int(conf, CONF_protocol) == PROT_ADB) { char *saved_host = conf_get_str(conf, CONF_host); dlg_label_change(ctrl, dlg, "-a: any, -d: usb, -e: emulator, or :serial"); @@ -277,7 +277,7 @@ static void config_host_handler(union control *ctrl, dlgparam *dlg, char *s = dlg_editbox_get(ctrl, dlg); if (conf_get_int(conf, CONF_protocol) == PROT_SERIAL) conf_set_str(conf, CONF_serline, s); -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM else if( cygterm_get_flag() && (conf_get_int(conf, CONF_protocol) == PROT_CYGTERM) ) { char *s = dlg_editbox_get(ctrl, dlg); conf_set_str(conf, CONF_cygcmd, s); @@ -308,7 +308,7 @@ static void config_port_handler(union control *ctrl, dlgparam *dlg, */ dlg_label_change(ctrl, dlg, "Speed"); sprintf(buf, "%d", conf_get_int(conf, CONF_serspeed)); -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM } else if( cygterm_get_flag() && (conf_get_int(conf, CONF_protocol) == PROT_CYGTERM) ) { dlg_label_change(ctrl, dlg, "Port (ignored)"); strcpy(buf, "-"); @@ -329,7 +329,7 @@ static void config_port_handler(union control *ctrl, dlgparam *dlg, if (conf_get_int(conf, CONF_protocol) == PROT_SERIAL) conf_set_int(conf, CONF_serspeed, i); -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM else if( cygterm_get_flag() && (conf_get_int(conf, CONF_protocol) == PROT_CYGTERM) ) ; #endif else @@ -637,7 +637,7 @@ static void printerbox_handler(union control *ctrl, dlgparam *dlg, if (ctrl->editbox.has_list) { dlg_listbox_clear(ctrl, dlg); dlg_listbox_add(ctrl, dlg, PRINTER_DISABLED_STRING); -#ifdef PRINTCLIPPORT +#ifdef MOD_PRINTCLIP dlg_listbox_add(ctrl, dlg, PRINT_TO_CLIPBOARD_STRING); #endif pe = printer_start_enum(&nprinters); @@ -645,7 +645,7 @@ static void printerbox_handler(union control *ctrl, dlgparam *dlg, dlg_listbox_add(ctrl, dlg, printer_get_name(pe, i)); printer_finish_enum(pe); } -#ifdef PRINTCLIPPORT +#ifdef MOD_PRINTCLIP printer = conf_get_str(conf, CONF_printer); if ( printer ) dlg_editbox_set(ctrl, dlg, conf_get_str(conf,CONF_printer) ) ; @@ -663,7 +663,7 @@ static void printerbox_handler(union control *ctrl, dlgparam *dlg, #endif } else if (event == EVENT_VALCHANGE) { char *printer = dlg_editbox_get(ctrl, dlg); -#ifdef PRINTCLIPPORT +#ifdef MOD_PRINTCLIP if (!strcmp(printer, PRINTER_DISABLED_STRING)) { //printer[0] = '\0'; conf_set_int(conf,CONF_printclip,0); @@ -739,7 +739,7 @@ static void sshbug_handler(union control *ctrl, dlgparam *dlg, } } -#ifdef PERSOPORT +#ifdef MOD_PERSO #include "kitty.h" int dlg_listbox_get(union control *ctrl, void *dlg, int index, char * pstr, int maxcount) ; int dlg_listbox_gettext(union control *ctrl, void *dlg, int index, char * pstr, int maxcount) ; @@ -833,9 +833,9 @@ static void folder_handler(union control *ctrl, dlgparam *dlg, #endif struct sessionsaver_data { -#ifdef PERSOPORT +#ifdef MOD_PERSO union control *editbox, *listbox, *clearbutton, *loadbutton, *savebutton, *delbutton, *createbutton, *delfolderbutton, *arrangebutton -#if (defined PERSOPORT) && (!defined FDJ) && (defined STARTBUTTON) +#if (defined MOD_PERSO) && (!defined FDJ) && (defined MOD_STARTBUTTON) , *startbutton #endif ; @@ -867,7 +867,7 @@ static bool load_selected_session( dlgparam *dlg, Conf *conf, bool *maybe_launch) { int i = dlg_listbox_index(ssd->listbox, dlg); -#ifdef PERSOPORT +#ifdef MOD_PERSO { char sessionname[1024] ; int j; @@ -899,7 +899,7 @@ static bool load_selected_session( } isdef = !strcmp(ssd->sesslist.sessions[i], "Default Settings"); load_settings(ssd->sesslist.sessions[i], conf); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( (get_param("INIFILE")==SAVEMODE_DIR) && GetDirectoryBrowseFlag() ) { conf_set_str(conf,CONF_folder,CurrentFolder) ; } else { @@ -922,7 +922,7 @@ static bool load_selected_session( return true; } -#ifdef PERSOPORT +#ifdef MOD_PERSO int filter_sessionname( const char * pattern, const char * sessionname, const char * folder, const char * savedsession ) { char buffer[4092] ; int lenpattern = strlen(pattern) ; @@ -978,7 +978,7 @@ static void sessionsaver_handler(union control *ctrl, dlgparam *dlg, if (event == EVENT_REFRESH) { if (ctrl == ssd->editbox) { -#ifdef PERSOPORT +#ifdef MOD_PERSO ctrlSessionEdit = ctrl ; #endif dlg_editbox_set(ctrl, dlg, ssd->savedsession); @@ -986,7 +986,7 @@ static void sessionsaver_handler(union control *ctrl, dlgparam *dlg, int i; dlg_update_start(ctrl, dlg); dlg_listbox_clear(ctrl, dlg); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( ssd->savedsession!=NULL ) strcpy( ssd->savedsession, dlg_editbox_get( ssd->editbox, dlg ) ) ; // ajout 0.63 pour que le filtre fonctionne ctrlSessionList = ctrl ; @@ -1049,7 +1049,7 @@ static void sessionsaver_handler(union control *ctrl, dlgparam *dlg, if (ctrl == ssd->editbox) { sfree(ssd->savedsession); ssd->savedsession = dlg_editbox_get(ctrl, dlg); -#ifdef PERSOPORT +#ifdef MOD_PERSO sessionsaver_handler( ctrlSessionList, dlg, data, EVENT_REFRESH ) ; #endif top = ssd->sesslist.nsessions; @@ -1080,7 +1080,7 @@ static void sessionsaver_handler(union control *ctrl, dlgparam *dlg, * double-click on the list box _and_ that session * contains a hostname. */ -#ifdef PERSOPORT +#ifdef MOD_PERSO if (load_selected_session(ssd, dlg, conf, &mbl) && (mbl && ctrl == ssd->listbox && conf_launchable(conf))) { if( conf_get_int(conf, CONF_protocol) != PROT_SERIAL ) { @@ -1119,7 +1119,7 @@ static void sessionsaver_handler(union control *ctrl, dlgparam *dlg, ssd->sesslist.sessions[i]); } { -#ifdef PERSOPORT +#ifdef MOD_PERSO conf_set_str( conf, CONF_folder, CurrentFolder ) ; if( conf_get_int(conf, CONF_protocol) != PROT_SERIAL ) { char buffer[1024] ; @@ -1148,13 +1148,13 @@ static void sessionsaver_handler(union control *ctrl, dlgparam *dlg, get_sesslist(&ssd->sesslist, true); dlg_refresh(ssd->editbox, dlg); dlg_refresh(ssd->listbox, dlg); -#ifdef PERSOPORT +#ifdef MOD_PERSO RepliqueToPuTTY( PUTTY_REG_POS ) ; #endif } else if (!ssd->midsession && ssd->delbutton && ctrl == ssd->delbutton) { int i = dlg_listbox_index(ssd->listbox, dlg); -#ifdef PERSOPORT +#ifdef MOD_PERSO { // Pour recuperer le bon index de la session a supprimer quand il y le filtre des sessions char sessionname[1024] ; int j; @@ -1172,7 +1172,7 @@ static void sessionsaver_handler(union control *ctrl, dlgparam *dlg, get_sesslist(&ssd->sesslist, true); dlg_refresh(ssd->listbox, dlg); } -#ifdef PERSOPORT +#ifdef MOD_PERSO ssd->savedsession[0]='\0' ; dlg_refresh(ssd->editbox, dlg) ; sessionsaver_handler( ctrlSessionList, dlg, data, EVENT_REFRESH ) ; @@ -1183,7 +1183,7 @@ static void sessionsaver_handler(union control *ctrl, dlgparam *dlg, dlg_end(dlg, 1); return; } -#ifdef PERSOPORT +#ifdef MOD_PERSO if( conf_get_int(conf, CONF_protocol) != PROT_SERIAL ) { char buffer[1024] ; strcpy( buffer, conf_get_str( conf, CONF_password) ) ; @@ -1230,8 +1230,8 @@ static void sessionsaver_handler(union control *ctrl, dlgparam *dlg, } else if (ctrl == ssd->cancelbutton) { dlg_end(dlg, 0); } -#ifdef PERSOPORT -#if (defined PERSOPORT) && (!defined FDJ) && (defined STARTBUTTON) +#ifdef MOD_PERSO +#if (defined MOD_PERSO) && (!defined FDJ) && (defined MOD_STARTBUTTON) else if (ctrl == ssd->startbutton) { if( conf_launchable(conf) ) { RunConfig(conf) ; @@ -1371,7 +1371,7 @@ static void charclass_handler(union control *ctrl, dlgparam *dlg, } struct colour_data { -#ifdef TUTTYPORT +#ifdef MOD_TUTTY union control *listbox, *redit, *gedit, *bedit, *button, *bold_checkbox, *underline_checkbox, *selected_checkbox; #else @@ -1380,7 +1380,7 @@ struct colour_data { }; static const char *const colours[] = { -#ifdef TUTTYPORT +#ifdef MOD_TUTTY "Default Foreground", "Default Bold Foreground", "Default Underlined Foreground", "Default Background", "Default Bold Background", @@ -1410,7 +1410,7 @@ static const char *const colours[] = { #endif }; -#ifdef TUTTYPORT +#ifdef MOD_TUTTY void dlg_control_enable(union control *ctrl, void *dlg, int enable); static const int itemcolour[] = { 0, 1, 2, 0, 1, 2, 0, 0, 3, 3, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, @@ -1473,7 +1473,7 @@ static void colour_handler(union control *ctrl, dlgparam *dlg, bool update = false, clear = false; int r, g, b; -#ifdef TUTTYPORT +#ifdef MOD_TUTTY if (ctrl == cd->bold_checkbox) { conf_set_int(conf,CONF_bold_colour,1); dlg_control_enable(cd->bold_checkbox, dlg,0); @@ -1515,7 +1515,7 @@ static void colour_handler(union control *ctrl, dlgparam *dlg, dlg_update_start(ctrl, dlg); dlg_listbox_clear(ctrl, dlg); for (i = 0; i < lenof(colours); i++) -#ifdef TUTTYPORT +#ifdef MOD_TUTTY /* This allows us to hide list items we don't need to * see: if bold-as-colour (or underline) turned off, we just hide those bold * choices to decrease user confusion. And, of course, it looks @@ -1554,7 +1554,7 @@ static void colour_handler(union control *ctrl, dlgparam *dlg, clear = true; } else { clear = false; -#ifdef TUTTYPORT +#ifdef MOD_TUTTY /* I know this looks a bit weird, but I just had no * other choice. Other way it would break existing code and * worse yet, existing saved session structure. @@ -1585,7 +1585,7 @@ static void colour_handler(union control *ctrl, dlgparam *dlg, i = dlg_listbox_index(cd->listbox, dlg); if (i >= 0) { -#ifdef TUTTYPORT +#ifdef MOD_TUTTY i = idxcolour[conf_get_int(conf,CONF_bold_colour)][conf_get_int(conf,CONF_under_colour)][conf_get_int(conf,CONF_sel_colour)][i]; #endif @@ -1609,7 +1609,7 @@ static void colour_handler(union control *ctrl, dlgparam *dlg, * EVENT_CALLBACK when it's finished and allow us to * pick up the results. */ -#ifdef TUTTYPORT +#ifdef MOD_TUTTY i = idxcolour[conf_get_int(conf,CONF_bold_colour)][conf_get_int(conf,CONF_under_colour)][conf_get_int(conf,CONF_sel_colour)][i]; #endif dlg_coloursel_start(ctrl, dlg, @@ -1625,7 +1625,7 @@ static void colour_handler(union control *ctrl, dlgparam *dlg, * return nonzero on success, or zero if the colour * selector did nothing (user hit Cancel, for example). */ -#ifdef TUTTYPORT +#ifdef MOD_TUTTY i = idxcolour[conf_get_int(conf,CONF_bold_colour)][conf_get_int(conf,CONF_under_colour)][conf_get_int(conf,CONF_sel_colour)][i]; #endif if (dlg_coloursel_results(ctrl, dlg, &r, &g, &b)) { @@ -2176,11 +2176,11 @@ void setup_config_box(struct controlbox *b, bool midsession, HELPCTX(no_help), sessionsaver_handler, P(ssd)); ssd->okbutton->button.isdefault = true; -#ifdef PERSOPORT +#ifdef MOD_PERSO if( GetConfigBoxHeight() > 7 ) ssd->okbutton->generic.column = 0 ; else #endif ssd->okbutton->generic.column = 3; -#if (defined PERSOPORT) && (!defined FDJ) && (defined STARTBUTTON) +#if (defined MOD_PERSO) && (!defined FDJ) && (defined MOD_STARTBUTTON) if( (!midsession)&&(!GetPuttyFlag()) ) { ssd->startbutton = ctrl_pushbutton(s, "Start", NO_SHORTCUT, HELPCTX(no_help), sessionsaver_handler, P(ssd)); if( GetConfigBoxHeight() > 7 ) ssd->startbutton->generic.column = 0 ; else ssd->startbutton->generic.column = 3; @@ -2189,7 +2189,7 @@ void setup_config_box(struct controlbox *b, bool midsession, ssd->cancelbutton = ctrl_pushbutton(s, "Cancel", 'c', HELPCTX(no_help), sessionsaver_handler, P(ssd)); ssd->cancelbutton->button.iscancel = true; -#ifdef PERSOPORT +#ifdef MOD_PERSO if( GetConfigBoxHeight() > 7 ) ssd->cancelbutton->generic.column = 0 ; else #endif ssd->cancelbutton->generic.column = 4; @@ -2229,12 +2229,12 @@ void setup_config_box(struct controlbox *b, bool midsession, "Raw", 'w', I(PROT_RAW), "Telnet", 't', I(PROT_TELNET), "Rlogin", 'i', I(PROT_RLOGIN), -#ifdef ADBPORT +#ifdef MOD_ADB "ADB", 'b', I(PROT_ADB), #endif NULL); } else { -#ifdef ADBPORT +#ifdef MOD_ADB if( GetADBFlag() ) ctrl_radiobuttons(s, "Connection type:", NO_SHORTCUT, 4, HELPCTX(session_hostname), @@ -2266,7 +2266,7 @@ void setup_config_box(struct controlbox *b, bool midsession, "Load, save or delete a stored session"); ctrl_columns(s, 2, 75, 25); get_sesslist(&ssd->sesslist, true); -#ifdef PERSOPORT +#ifdef MOD_PERSO ssd->editbox = ctrl_editbox(s, "Saved Sessions/New Folder", 'e', 100, HELPCTX(session_saved), sessionsaver_handler, P(ssd), P(NULL)); @@ -2294,12 +2294,12 @@ void setup_config_box(struct controlbox *b, bool midsession, HELPCTX(session_saved), sessionsaver_handler, P(ssd)); ssd->listbox->generic.column = 0; -#ifdef PERSOPORT +#ifdef MOD_PERSO ssd->listbox->listbox.height = GetConfigBoxHeight() ; #else ssd->listbox->listbox.height = 7; #endif -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM if( cygterm_get_flag() ) ssd->listbox->listbox.height-- ; #endif if (!midsession) { @@ -2315,7 +2315,7 @@ void setup_config_box(struct controlbox *b, bool midsession, ssd->loadbutton = NULL; } /* "Save" button is permitted mid-session. */ -#ifdef PERSOPORT +#ifdef MOD_PERSO if( !GetReadOnlyFlag() ) { if( get_param("INIFILE") == 1 ) ssd->savebutton = ctrl_pushbutton(s, "Save (f)", 'v', HELPCTX(session_saved), sessionsaver_handler, P(ssd)); @@ -2439,7 +2439,7 @@ void setup_config_box(struct controlbox *b, bool midsession, ctrl_text(s, "(Log file name can contain &Y, &M, &D for date," " &T for time, &H for host name, and &P for port number)", HELPCTX(logging_filename)); -#ifdef PERSOPORT +#ifdef MOD_PERSO ctrl_editbox(s, "Log rotation delay (sec)", NO_SHORTCUT, 50, HELPCTX(no_help), conf_editbox_handler, I(CONF_logtimerotation), I(-1) ) ; @@ -2473,7 +2473,7 @@ void setup_config_box(struct controlbox *b, bool midsession, } /* rutty: Session/Scripting panel */ -#ifdef RUTTYPORT +#ifdef MOD_RUTTY if( !GetPuttyFlag() && (GetRuttyFlag()>0) ) { ctrl_settitle(b, "Session/Scripting", "Scripting (RuTTY patch)"); s = ctrl_getset(b, "Session/Scripting", "Start", NULL); @@ -2584,7 +2584,12 @@ void setup_config_box(struct controlbox *b, bool midsession, conf_radiobutton_bool_handler, I(CONF_bksp_is_delete), "Control-H", I(0), "Control-? (127)", I(1), NULL); -#ifdef PERSOPORT +#ifdef MOD_PERSO + ctrl_radiobuttons(s, "The Enter key", 'y', 2, + HELPCTX(no_help), + conf_radiobutton_handler, + I(CONF_enter_sends_crlf), + "CR", I(0), "CR LF", I(1), NULL); ctrl_radiobuttons(s, "The Home and End keys", 'e', 3, HELPCTX(keyboard_homeend), conf_radiobutton_handler, @@ -2605,7 +2610,7 @@ void setup_config_box(struct controlbox *b, bool midsession, I(CONF_funky_type), "ESC[n~", I(0), "Linux", I(1), "Xterm R6", I(2), "VT400", I(3), "VT100+", I(4), "SCO", I(5), -#ifdef TUTTYPORT +#ifdef MOD_TUTTY // "AT&T 513", I(6), // "Sun Xterm", I(8), #endif @@ -2638,7 +2643,7 @@ void setup_config_box(struct controlbox *b, bool midsession, "Make default system alert sound", I(BELL_DEFAULT), "Visual bell (flash window)", I(BELL_VISUAL), NULL); -#ifdef PERSOPORT +#ifdef MOD_PERSO ctrl_checkbox(s, "Put window on foreground on bell", NO_SHORTCUT, HELPCTX(no_help), conf_checkbox_handler, I(CONF_foreground_on_bell) ) ; @@ -2791,7 +2796,7 @@ s = ctrl_getset(b, "Terminal/Bell", "overload", conf_editbox_handler, I(CONF_window_border), I(-1)); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( !GetPuttyFlag() ) { /* * Brad's The Window/Position & Icon panel. @@ -2824,7 +2829,7 @@ s = ctrl_getset(b, "Terminal/Bell", "overload", } #endif -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) if( !GetPuttyFlag() && GetBackgroundImageFlag() ) { /* * The Window/Background panel. @@ -2848,7 +2853,7 @@ s = ctrl_getset(b, "Terminal/Bell", "overload", s = ctrl_getset(b, "Window/Back.&Image", "bg_wp_img_settings", "Desktop and image settings"); - ctrl_editbox(s, "Opacity:", NO_SHORTCUT, 20, + ctrl_editbox(s, "Opacity: (negative with Image for gradient)", NO_SHORTCUT, 20, HELPCTX(no_help), conf_editbox_handler, I(CONF_bg_opacity), I(-1) ) ; @@ -2859,7 +2864,7 @@ s = ctrl_getset(b, "Terminal/Bell", "overload", s = ctrl_getset(b, "Window/Back.&Image", "bg_img_settings", "Image settings"); - ctrl_filesel(s, "Image file:", NO_SHORTCUT, + ctrl_filesel(s, "Image file: (or #RRGGBB for gradient)", NO_SHORTCUT, FILTER_IMAGE_FILES, FALSE, "Select background image file", HELPCTX(no_help), conf_filesel_handler, I(CONF_bg_image_filename) ); @@ -2893,7 +2898,7 @@ s = ctrl_getset(b, "Terminal/Bell", "overload", } #endif -#ifdef PERSOPORT +#ifdef MOD_PERSO static char transTitle[256]="Window/Transparency" ; if( !GetPuttyFlag() ) { if( GetTransparencyFlag() ) ctrl_settitle(b, transTitle, "Options controlling transparency"); @@ -2924,7 +2929,7 @@ s = ctrl_getset(b, "Terminal/Bell", "overload", ctrl_editbox(s, "Window title:", 't', 100, HELPCTX(appearance_title), conf_editbox_handler, I(CONF_wintitle), I(1)); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( !GetPuttyFlag() ) { ctrl_text(s, " %%f: folder name", HELPCTX(appearance_title)); ctrl_text(s, " %%h: hostname", HELPCTX(appearance_title)); @@ -2944,7 +2949,7 @@ if( !GetPuttyFlag() ) { ctrl_checkbox(s, "Warn before closing window", 'w', HELPCTX(behaviour_closewarn), conf_checkbox_handler, I(CONF_warn_on_close)); -#ifdef DISABLEALTGRPORT +#ifdef MOD_DISABLEALTGR if( !GetPuttyFlag() ) { ctrl_checkbox(s, "Disable AltGr menu", NO_SHORTCUT, HELPCTX(no_help), @@ -2986,12 +2991,6 @@ if( !GetPuttyFlag() ) { HELPCTX(translation_utf8linedraw), conf_checkbox_handler, I(CONF_utf8linedraw)); -#ifdef ACSPORT - ctrl_checkbox(s, "Allow ACS line drawing in UTF", NO_SHORTCUT, - HELPCTX(no_help), - conf_checkbox_handler, I(CONF_acs_in_utf)); -#endif - /* * The Window/Selection panel. */ @@ -3088,7 +3087,7 @@ if( !GetPuttyFlag() ) { "Both", I(3), NULL); -#ifdef TUTTYPORT +#ifdef MOD_TUTTY cd = (struct colour_data *) ctrl_alloc(b, sizeof(struct colour_data)); memset(cd , 0, sizeof(*cd )); cd->bold_checkbox = @@ -3110,7 +3109,7 @@ if( !GetPuttyFlag() ) { HELPCTX(colours_config)); ctrl_columns(s, 2, 67, 33); cd = (struct colour_data *)ctrl_alloc(b, sizeof(struct colour_data)); -#ifndef TUTTYPORT +#ifndef MOD_TUTTY cd = (struct colour_data *)ctrl_alloc(b, sizeof(struct colour_data)); #endif cd->listbox = ctrl_listbox(s, "Select a colour to adjust:", 'u', @@ -3147,7 +3146,7 @@ if( !GetPuttyFlag() ) { HELPCTX(connection_keepalive), conf_editbox_handler, I(CONF_ping_interval), I(-1)); -#ifdef PERSOPORT +#ifdef MOD_PERSO ctrl_editbox(s, "Anti-idle string", NO_SHORTCUT, 50, HELPCTX(no_help), conf_editbox_handler, I(CONF_antiidle), I(1) ) ; @@ -3177,7 +3176,7 @@ if( !GetPuttyFlag() ) { NULL); #endif -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT if( !GetPuttyFlag() && GetAutoreconnectFlag() ) { s = ctrl_getset(b, "Connection", "reconnect", "Reconnect options"); ctrl_checkbox(s, "Attempt to reconnect on system wakeup", NO_SHORTCUT, HELPCTX(no_help), conf_checkbox_handler, I(CONF_wakeup_reconnect)) ; @@ -3195,7 +3194,7 @@ if( !GetPuttyFlag() ) { HELPCTX(connection_loghost), conf_editbox_handler, I(CONF_loghost), I(1)); } -#ifdef PORTKNOCKINGPORT +#ifdef MOD_PORTKNOCKING // port knocking panel if( !GetPuttyFlag() ) { // ctrl_settitle(b, "Connection/Port knocking", "Options controlling port knocking") ; @@ -3241,9 +3240,9 @@ if( !GetPuttyFlag() ) { sfree(userlabel); } -#ifdef PERSOPORT +#ifdef MOD_PERSO if( !GetPuttyFlag() ) { -#ifndef NO_PASSWORD +#ifndef MOD_NOPASSWORD c = ctrl_editbox(s, "Auto-login password", NO_SHORTCUT, 50, HELPCTX(no_help), conf_editbox_handler, I(CONF_password), I(1) ) ; @@ -3452,7 +3451,7 @@ if( !GetPuttyFlag() ) { "exist without looking strange.", HELPCTX(no_help)); } -#ifdef PERSOPORT +#ifdef MOD_PERSO if (!midsession) { s = ctrl_getset(b, "Connection/SSH", "pscp", "PSCP integration") ; ctrl_checkbox(s, "Send file in current directory", NO_SHORTCUT, @@ -3855,7 +3854,7 @@ if( !GetPuttyFlag() ) { pfd->listbox = ctrl_listbox(s, NULL, NO_SHORTCUT, HELPCTX(ssh_tunnels_portfwd), portfwd_handler, P(pfd)); -#ifdef PERSOPORT +#ifdef MOD_PERSO pfd->listbox->listbox.height = 12 ; #else pfd->listbox->listbox.height = 3; @@ -3956,7 +3955,7 @@ if( !GetPuttyFlag() ) { sshbug_handler, I(CONF_sshbug_rsa1)); } } -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM // z-modem panel if( (!GetPuttyFlag())&&GetZModemFlag() ) { ctrl_settitle(b, "Connection/ZModem", @@ -4001,7 +4000,7 @@ if( !GetPuttyFlag() ) { /**/ } #endif -#ifdef PERSOPORT +#ifdef MOD_PERSO if( !GetPuttyFlag() ) { ctrl_settitle(b, "Comment", "Options comments"); s = ctrl_getset(b, "Comment", "freecomment", @@ -4018,7 +4017,7 @@ if( !GetPuttyFlag() ) { #endif } -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM /* * The standard directory-selector handler expects the main `context' * field to contain the `offsetof' a Filename field in the diff --git a/0.72_My_PuTTY/cproxy.c b/0.73_My_PuTTY/cproxy.c similarity index 100% rename from 0.72_My_PuTTY/cproxy.c rename to 0.73_My_PuTTY/cproxy.c diff --git a/0.72_My_PuTTY/defs.h b/0.73_My_PuTTY/defs.h similarity index 100% rename from 0.72_My_PuTTY/defs.h rename to 0.73_My_PuTTY/defs.h diff --git a/0.72_My_PuTTY/dialog.c b/0.73_My_PuTTY/dialog.c similarity index 99% rename from 0.72_My_PuTTY/dialog.c rename to 0.73_My_PuTTY/dialog.c index f903667..2c83f10 100644 --- a/0.72_My_PuTTY/dialog.c +++ b/0.73_My_PuTTY/dialog.c @@ -461,7 +461,7 @@ void ctrl_free(union control *ctrl) case CTRL_FILESELECT: sfree(ctrl->fileselect.title); break; -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM case CTRL_DIRECTORYSELECT: sfree(ctrl->fileselect.title); break; @@ -470,7 +470,7 @@ void ctrl_free(union control *ctrl) sfree(ctrl); } -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM union control *ctrl_directorysel(struct controlset *s,char *label,char shortcut, char *title, intorptr helpctx, handler_fn handler, diff --git a/0.72_My_PuTTY/dialog.h b/0.73_My_PuTTY/dialog.h similarity index 99% rename from 0.72_My_PuTTY/dialog.h rename to 0.73_My_PuTTY/dialog.h index 0e00970..283a423 100644 --- a/0.72_My_PuTTY/dialog.h +++ b/0.73_My_PuTTY/dialog.h @@ -29,7 +29,7 @@ enum { CTRL_COLUMNS, /* divide window into columns */ CTRL_FILESELECT, /* label plus filename selector */ CTRL_FONTSELECT, /* label plus font selector */ -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM CTRL_DIRECTORYSELECT, /* label plus directory selector */ #endif CTRL_TABDELAY /* see `tabdelay' below */ @@ -407,7 +407,7 @@ union control { STANDARD_PREFIX; char shortcut; } fontselect; -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM struct { STANDARD_PREFIX; char shortcut; @@ -545,7 +545,7 @@ union control *ctrl_checkbox(struct controlset *, const char *label, char shortcut, intorptr helpctx, handler_fn handler, intorptr context); union control *ctrl_tabdelay(struct controlset *, union control *); -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM union control *ctrl_directorysel(struct controlset *,char *label,char shortcut, char *title, intorptr helpctx, @@ -585,7 +585,7 @@ void dlg_filesel_set(union control *ctrl, dlgparam *dp, Filename *fn); Filename *dlg_filesel_get(union control *ctrl, dlgparam *dp); void dlg_fontsel_set(union control *ctrl, dlgparam *dp, FontSpec *fn); FontSpec *dlg_fontsel_get(union control *ctrl, dlgparam *dp); -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM void dlg_directorysel_set(union control *ctrl, void *dlg, Filename fn); void dlg_directorysel_get(union control *ctrl, void *dlg, Filename *fn); #endif @@ -677,7 +677,7 @@ int ctrl_path_elements(const char *path); * or INT_MAX if the paths are identical. */ int ctrl_path_compare(const char *p1, const char *p2); -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM /* * The standard directory-selector handler expects the main `context' * field to contain the `offsetof' a Filename field in the diff --git a/0.72_My_PuTTY/ecc.c b/0.73_My_PuTTY/ecc.c similarity index 100% rename from 0.72_My_PuTTY/ecc.c rename to 0.73_My_PuTTY/ecc.c diff --git a/0.72_My_PuTTY/ecc.h b/0.73_My_PuTTY/ecc.h similarity index 100% rename from 0.72_My_PuTTY/ecc.h rename to 0.73_My_PuTTY/ecc.h diff --git a/0.72_My_PuTTY/empty.h b/0.73_My_PuTTY/empty.h similarity index 100% rename from 0.72_My_PuTTY/empty.h rename to 0.73_My_PuTTY/empty.h diff --git a/0.72_My_PuTTY/errsock.c b/0.73_My_PuTTY/errsock.c similarity index 98% rename from 0.72_My_PuTTY/errsock.c rename to 0.73_My_PuTTY/errsock.c index 9ab7c3d..e691dec 100644 --- a/0.72_My_PuTTY/errsock.c +++ b/0.73_My_PuTTY/errsock.c @@ -50,7 +50,6 @@ static const SocketVtable ErrorSocket_sockvt = { NULL /* write */, NULL /* write_oob */, NULL /* write_eof */, - NULL /* flush */, NULL /* set_frozen */, sk_error_socket_error, sk_error_peer_info, diff --git a/0.72_My_PuTTY/fuzzterm.c b/0.73_My_PuTTY/fuzzterm.c similarity index 100% rename from 0.72_My_PuTTY/fuzzterm.c rename to 0.73_My_PuTTY/fuzzterm.c diff --git a/0.72_My_PuTTY/import.c b/0.73_My_PuTTY/import.c similarity index 100% rename from 0.72_My_PuTTY/import.c rename to 0.73_My_PuTTY/import.c diff --git a/0.72_My_PuTTY/ldisc.c b/0.73_My_PuTTY/ldisc.c similarity index 99% rename from 0.72_My_PuTTY/ldisc.c rename to 0.73_My_PuTTY/ldisc.c index a27ff39..4c74b45 100644 --- a/0.72_My_PuTTY/ldisc.c +++ b/0.73_My_PuTTY/ldisc.c @@ -21,7 +21,7 @@ (backend_ldisc_option_state(ldisc->backend, LD_EDIT)))) /* rutty: special entry point for local data (in windows.c) */ -#ifdef RUTTYPORT +#ifdef MOD_RUTTY int GetPuttyFlag(void) ; int GetRuttyFlag(void) ; @@ -141,7 +141,7 @@ void ldisc_free(Ldisc *ldisc) } /* rutty: */ -#ifdef RUTTYPORT +#ifdef MOD_RUTTY #include "script.h" extern ScriptData scriptdata; /* in window.c */ #endif /* rutty */ @@ -160,7 +160,7 @@ void ldisc_send(Ldisc *ldisc, const void *vbuf, int len, bool interactive) assert(len); /* rutty: */ -#ifdef RUTTYPORT +#ifdef MOD_RUTTY if( !GetPuttyFlag() && (GetRuttyFlag()>0) ) { script_local(&scriptdata, buf,len); } #endif /* rutty */ diff --git a/0.72_My_PuTTY/ldisc.h b/0.73_My_PuTTY/ldisc.h similarity index 100% rename from 0.72_My_PuTTY/ldisc.h rename to 0.73_My_PuTTY/ldisc.h diff --git a/0.72_My_PuTTY/licence.h b/0.73_My_PuTTY/licence.h similarity index 100% rename from 0.72_My_PuTTY/licence.h rename to 0.73_My_PuTTY/licence.h diff --git a/0.72_My_PuTTY/logging.c b/0.73_My_PuTTY/logging.c similarity index 99% rename from 0.72_My_PuTTY/logging.c rename to 0.73_My_PuTTY/logging.c index 2766fb1..ea0c2ea 100644 --- a/0.72_My_PuTTY/logging.c +++ b/0.73_My_PuTTY/logging.c @@ -25,7 +25,7 @@ struct LogContext { static Filename *xlatlognam(Filename *s, char *hostname, int port, struct tm *tm); -#ifdef PERSOPORT +#ifdef MOD_PERSO int GetPuttyFlag(void) ; int mkdir(const char *path, int mode); int insert( char * ch, const char * c, const int ipos ) ; @@ -156,7 +156,7 @@ static void logwrite(LogContext *ctx, ptrlen data) * to one of L_OPENING, L_OPEN or L_ERROR. Hence we process all of * those three _after_ processing L_CLOSED. */ -#ifdef PERSOPORT +#ifdef MOD_PERSO if( !LogMode ) return ; if( timestamp_newfile ) { if (ctx->state == L_OPEN) { logfclose(ctx);} @@ -171,7 +171,7 @@ static void logwrite(LogContext *ctx, ptrlen data) bufchain_add(&ctx->queue, data.ptr, data.len); } else if (ctx->state == L_OPEN) { assert(ctx->lgfp); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( !GetPuttyFlag() ) { if( timestamp_newline ) { log_writetimestamp( ctx ) ; timestamp_newline = 0 ; } char * c = (char*)(data.ptr+data.len-1) ; @@ -303,7 +303,7 @@ void logfopen(LogContext *ctx) xlatlognam(conf_get_filename(ctx->conf, CONF_logfilename), conf_get_str(ctx->conf, CONF_host), conf_get_int(ctx->conf, CONF_port), &tm); -#ifdef PERSOPORT +#ifdef MOD_PERSO test_dir( ctx->currlogfilename ) ; #endif @@ -585,7 +585,7 @@ void log_reconfig(LogContext *ctx, Conf *conf) static Filename *xlatlognam(Filename *src, char *hostname, int port, struct tm *tm) { -#ifdef PERSOPORT +#ifdef MOD_PERSO char buf[100], *bufp; #else char buf[32], *bufp; @@ -619,7 +619,7 @@ static Filename *xlatlognam(Filename *src, char *hostname, int port, case 't': size = strftime(buf, sizeof(buf), "%H%M%S", tm); break; -#ifdef PERSOPORT +#ifdef MOD_PERSO case 'h': strcpy(buf,hostname) ; int i ; while( (i=poss(":",buf))>0 ) { buf[i-1]='-' ; } // Pour gerer IPv6 diff --git a/0.72_My_PuTTY/mainchan.c b/0.73_My_PuTTY/mainchan.c similarity index 100% rename from 0.72_My_PuTTY/mainchan.c rename to 0.73_My_PuTTY/mainchan.c diff --git a/0.72_My_PuTTY/marshal.c b/0.73_My_PuTTY/marshal.c similarity index 100% rename from 0.72_My_PuTTY/marshal.c rename to 0.73_My_PuTTY/marshal.c diff --git a/0.72_My_PuTTY/marshal.h b/0.73_My_PuTTY/marshal.h similarity index 100% rename from 0.72_My_PuTTY/marshal.h rename to 0.73_My_PuTTY/marshal.h diff --git a/0.72_My_PuTTY/memory.c b/0.73_My_PuTTY/memory.c similarity index 100% rename from 0.72_My_PuTTY/memory.c rename to 0.73_My_PuTTY/memory.c diff --git a/0.72_My_PuTTY/minibidi.c b/0.73_My_PuTTY/minibidi.c similarity index 100% rename from 0.72_My_PuTTY/minibidi.c rename to 0.73_My_PuTTY/minibidi.c diff --git a/0.72_My_PuTTY/misc.c b/0.73_My_PuTTY/misc.c similarity index 99% rename from 0.72_My_PuTTY/misc.c rename to 0.73_My_PuTTY/misc.c index 47099de..0bb7b31 100644 --- a/0.72_My_PuTTY/misc.c +++ b/0.73_My_PuTTY/misc.c @@ -105,7 +105,7 @@ bool conf_launchable(Conf *conf) { if (conf_get_int(conf, CONF_protocol) == PROT_SERIAL) return conf_get_str(conf, CONF_serline)[0] != 0; -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM else if (conf_get_int(conf, CONF_protocol) == PROT_CYGTERM) return conf_get_str(conf, CONF_cygcmd)[0] != 0; #endif @@ -117,7 +117,7 @@ char const *conf_dest(Conf *conf) { if (conf_get_int(conf, CONF_protocol) == PROT_SERIAL) return conf_get_str(conf, CONF_serline); -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM else if (conf_get_int(conf, CONF_protocol) == PROT_CYGTERM) return conf_get_str(conf, CONF_cygcmd) ; #endif diff --git a/0.72_My_PuTTY/misc.h b/0.73_My_PuTTY/misc.h similarity index 100% rename from 0.72_My_PuTTY/misc.h rename to 0.73_My_PuTTY/misc.h diff --git a/0.72_My_PuTTY/miscucs.c b/0.73_My_PuTTY/miscucs.c similarity index 100% rename from 0.72_My_PuTTY/miscucs.c rename to 0.73_My_PuTTY/miscucs.c diff --git a/0.72_My_PuTTY/mpint.c b/0.73_My_PuTTY/mpint.c similarity index 97% rename from 0.72_My_PuTTY/mpint.c rename to 0.73_My_PuTTY/mpint.c index 72ae0ea..bad88ec 100644 --- a/0.72_My_PuTTY/mpint.c +++ b/0.73_My_PuTTY/mpint.c @@ -1,2395 +1,2395 @@ -#include -#include -#include - -#include "defs.h" -#include "misc.h" -#include "puttymem.h" - -#include "mpint.h" -#include "mpint_i.h" - -#define SIZE_T_BITS (CHAR_BIT * sizeof(size_t)) - -/* - * Inline helpers to take min and max of size_t values, used - * throughout this code. - */ -static inline size_t size_t_min(size_t a, size_t b) -{ - return a < b ? a : b; -} -static inline size_t size_t_max(size_t a, size_t b) -{ - return a > b ? a : b; -} - -/* - * Helper to fetch a word of data from x with array overflow checking. - * If x is too short to have that word, 0 is returned. - */ -static inline BignumInt mp_word(mp_int *x, size_t i) -{ - return i < x->nw ? x->w[i] : 0; -} - -static mp_int *mp_make_sized(size_t nw) -{ - mp_int *x = snew_plus(mp_int, nw * sizeof(BignumInt)); - assert(nw); /* we outlaw the zero-word mp_int */ - x->nw = nw; - x->w = snew_plus_get_aux(x); - mp_clear(x); - return x; -} - -mp_int *mp_new(size_t maxbits) -{ - size_t words = (maxbits + BIGNUM_INT_BITS - 1) / BIGNUM_INT_BITS; - return mp_make_sized(words); -} - -mp_int *mp_from_integer(uintmax_t n) -{ - mp_int *x = mp_make_sized( - (sizeof(n) + BIGNUM_INT_BYTES - 1) / BIGNUM_INT_BYTES); - for (size_t i = 0; i < x->nw; i++) - x->w[i] = n >> (i * BIGNUM_INT_BITS); - return x; -} - -size_t mp_max_bytes(mp_int *x) -{ - return x->nw * BIGNUM_INT_BYTES; -} - -size_t mp_max_bits(mp_int *x) -{ - return x->nw * BIGNUM_INT_BITS; -} - -void mp_free(mp_int *x) -{ - mp_clear(x); - smemclr(x, sizeof(*x)); - sfree(x); -} - -void mp_dump(FILE *fp, const char *prefix, mp_int *x, const char *suffix) -{ - fprintf(fp, "%s0x", prefix); - for (size_t i = mp_max_bytes(x); i-- > 0 ;) - fprintf(fp, "%02X", mp_get_byte(x, i)); - fputs(suffix, fp); -} - -void mp_copy_into(mp_int *dest, mp_int *src) -{ - size_t copy_nw = size_t_min(dest->nw, src->nw); - memmove(dest->w, src->w, copy_nw * sizeof(BignumInt)); - smemclr(dest->w + copy_nw, (dest->nw - copy_nw) * sizeof(BignumInt)); -} - -/* - * Conditional selection is done by negating 'which', to give a mask - * word which is all 1s if which==1 and all 0s if which==0. Then you - * can select between two inputs a,b without data-dependent control - * flow by XORing them to get their difference; ANDing with the mask - * word to replace that difference with 0 if which==0; and XORing that - * into a, which will either turn it into b or leave it alone. - * - * This trick will be used throughout this code and taken as read the - * rest of the time (or else I'd be here all week typing comments), - * but I felt I ought to explain it in words _once_. - */ -void mp_select_into(mp_int *dest, mp_int *src0, mp_int *src1, - unsigned which) -{ - BignumInt mask = -(BignumInt)(1 & which); - for (size_t i = 0; i < dest->nw; i++) { - BignumInt srcword0 = mp_word(src0, i), srcword1 = mp_word(src1, i); - dest->w[i] = srcword0 ^ ((srcword1 ^ srcword0) & mask); - } -} - -void mp_cond_swap(mp_int *x0, mp_int *x1, unsigned swap) -{ - assert(x0->nw == x1->nw); - volatile BignumInt mask = -(BignumInt)(1 & swap); - for (size_t i = 0; i < x0->nw; i++) { - BignumInt diff = (x0->w[i] ^ x1->w[i]) & mask; - x0->w[i] ^= diff; - x1->w[i] ^= diff; - } -} - -void mp_clear(mp_int *x) -{ - smemclr(x->w, x->nw * sizeof(BignumInt)); -} - -void mp_cond_clear(mp_int *x, unsigned clear) -{ - BignumInt mask = ~-(BignumInt)(1 & clear); - for (size_t i = 0; i < x->nw; i++) - x->w[i] &= mask; -} - -/* - * Common code between mp_from_bytes_{le,be} which reads bytes in an - * arbitrary arithmetic progression. - */ -static mp_int *mp_from_bytes_int(ptrlen bytes, size_t m, size_t c) -{ - size_t nw = (bytes.len + BIGNUM_INT_BYTES - 1) / BIGNUM_INT_BYTES; - nw = size_t_max(nw, 1); - mp_int *n = mp_make_sized(nw); - for (size_t i = 0; i < bytes.len; i++) - n->w[i / BIGNUM_INT_BYTES] |= - (BignumInt)(((const unsigned char *)bytes.ptr)[m*i+c]) << - (8 * (i % BIGNUM_INT_BYTES)); - return n; -} - -mp_int *mp_from_bytes_le(ptrlen bytes) -{ - return mp_from_bytes_int(bytes, 1, 0); -} - -mp_int *mp_from_bytes_be(ptrlen bytes) -{ - return mp_from_bytes_int(bytes, -1, bytes.len - 1); -} - -static mp_int *mp_from_words(size_t nw, const BignumInt *w) -{ - mp_int *x = mp_make_sized(nw); - memcpy(x->w, w, x->nw * sizeof(BignumInt)); - return x; -} - -/* - * Decimal-to-binary conversion: just go through the input string - * adding on the decimal value of each digit, and then multiplying the - * number so far by 10. - */ -mp_int *mp_from_decimal_pl(ptrlen decimal) -{ - /* 196/59 is an upper bound (and also a continued-fraction - * convergent) for log2(10), so this conservatively estimates the - * number of bits that will be needed to store any number that can - * be written in this many decimal digits. */ - assert(decimal.len < (~(size_t)0) / 196); - size_t bits = 196 * decimal.len / 59; - - /* Now round that up to words. */ - size_t words = bits / BIGNUM_INT_BITS + 1; - - mp_int *x = mp_make_sized(words); - for (size_t i = 0; i < decimal.len; i++) { - mp_add_integer_into(x, x, ((char *)decimal.ptr)[i] - '0'); - - if (i+1 == decimal.len) - break; - - mp_mul_integer_into(x, x, 10); - } - return x; -} - -mp_int *mp_from_decimal(const char *decimal) -{ - return mp_from_decimal_pl(ptrlen_from_asciz(decimal)); -} - -/* - * Hex-to-binary conversion: _algorithmically_ simpler than decimal - * (none of those multiplications by 10), but there's some fiddly - * bit-twiddling needed to process each hex digit without diverging - * control flow depending on whether it's a letter or a number. - */ -mp_int *mp_from_hex_pl(ptrlen hex) -{ - assert(hex.len <= (~(size_t)0) / 4); - size_t bits = hex.len * 4; - size_t words = (bits + BIGNUM_INT_BITS - 1) / BIGNUM_INT_BITS; - words = size_t_max(words, 1); - mp_int *x = mp_make_sized(words); - for (size_t nibble = 0; nibble < hex.len; nibble++) { - BignumInt digit = ((char *)hex.ptr)[hex.len-1 - nibble]; - - BignumInt lmask = ~-((BignumInt)((digit-'a')|('f'-digit)) - >> (BIGNUM_INT_BITS-1)); - BignumInt umask = ~-((BignumInt)((digit-'A')|('F'-digit)) - >> (BIGNUM_INT_BITS-1)); - - BignumInt digitval = digit - '0'; - digitval ^= (digitval ^ (digit - 'a' + 10)) & lmask; - digitval ^= (digitval ^ (digit - 'A' + 10)) & umask; - digitval &= 0xF; /* at least be _slightly_ nice about weird input */ - - size_t word_idx = nibble / (BIGNUM_INT_BYTES*2); - size_t nibble_within_word = nibble % (BIGNUM_INT_BYTES*2); - x->w[word_idx] |= digitval << (nibble_within_word * 4); - } - return x; -} - -mp_int *mp_from_hex(const char *hex) -{ - return mp_from_hex_pl(ptrlen_from_asciz(hex)); -} - -mp_int *mp_copy(mp_int *x) -{ - return mp_from_words(x->nw, x->w); -} - -uint8_t mp_get_byte(mp_int *x, size_t byte) -{ - return 0xFF & (mp_word(x, byte / BIGNUM_INT_BYTES) >> - (8 * (byte % BIGNUM_INT_BYTES))); -} - -unsigned mp_get_bit(mp_int *x, size_t bit) -{ - return 1 & (mp_word(x, bit / BIGNUM_INT_BITS) >> - (bit % BIGNUM_INT_BITS)); -} - -uintmax_t mp_get_integer(mp_int *x) -{ - uintmax_t toret = 0; - for (size_t i = x->nw; i-- > 0 ;) { - /* Shift in two stages to avoid undefined behaviour if the - * shift count equals the integer width */ - toret = (toret << (BIGNUM_INT_BITS/2)) << (BIGNUM_INT_BITS/2); - toret |= x->w[i]; - } - return toret; -} - -void mp_set_bit(mp_int *x, size_t bit, unsigned val) -{ - size_t word = bit / BIGNUM_INT_BITS; - assert(word < x->nw); - - unsigned shift = (bit % BIGNUM_INT_BITS); - - x->w[word] &= ~((BignumInt)1 << shift); - x->w[word] |= (BignumInt)(val & 1) << shift; -} - -/* - * Helper function used here and there to normalise any nonzero input - * value to 1. - */ -static inline unsigned normalise_to_1(BignumInt n) -{ - n = (n >> 1) | (n & 1); /* ensure top bit is clear */ - n = (BignumInt)(-n) >> (BIGNUM_INT_BITS - 1); /* normalise to 0 or 1 */ - return n; -} -static inline unsigned normalise_to_1_u64(uint64_t n) -{ - n = (n >> 1) | (n & 1); /* ensure top bit is clear */ - n = (-n) >> 63; /* normalise to 0 or 1 */ - return n; -} - -/* - * Find the highest nonzero word in a number. Returns the index of the - * word in x->w, and also a pair of output uint64_t in which that word - * appears in the high one shifted left by 'shift_wanted' bits, the - * words immediately below it occupy the space to the right, and the - * words below _that_ fill up the low one. - * - * If there is no nonzero word at all, the passed-by-reference output - * variables retain their original values. - */ -static inline void mp_find_highest_nonzero_word_pair( - mp_int *x, size_t shift_wanted, size_t *index, - uint64_t *hi, uint64_t *lo) -{ - uint64_t curr_hi = 0, curr_lo = 0; - - for (size_t curr_index = 0; curr_index < x->nw; curr_index++) { - BignumInt curr_word = x->w[curr_index]; - unsigned indicator = normalise_to_1(curr_word); - - curr_lo = (BIGNUM_INT_BITS < 64 ? (curr_lo >> BIGNUM_INT_BITS) : 0) | - (curr_hi << (64 - BIGNUM_INT_BITS)); - curr_hi = (BIGNUM_INT_BITS < 64 ? (curr_hi >> BIGNUM_INT_BITS) : 0) | - ((uint64_t)curr_word << shift_wanted); - - if (hi) *hi ^= (curr_hi ^ *hi ) & -(uint64_t)indicator; - if (lo) *lo ^= (curr_lo ^ *lo ) & -(uint64_t)indicator; - if (index) *index ^= (curr_index ^ *index) & -(size_t) indicator; - } -} - -size_t mp_get_nbits(mp_int *x) -{ - /* Sentinel values in case there are no bits set at all: we - * imagine that there's a word at position -1 (i.e. the topmost - * fraction word) which is all 1s, because that way, we handle a - * zero input by considering its highest set bit to be the top one - * of that word, i.e. just below the units digit, i.e. at bit - * index -1, i.e. so we'll return 0 on output. */ - size_t hiword_index = -(size_t)1; - uint64_t hiword64 = ~(BignumInt)0; - - /* - * Find the highest nonzero word and its index. - */ - mp_find_highest_nonzero_word_pair(x, 0, &hiword_index, &hiword64, NULL); - BignumInt hiword = hiword64; /* in case BignumInt is a narrower type */ - - /* - * Find the index of the highest set bit within hiword. - */ - BignumInt hibit_index = 0; - for (size_t i = (1 << (BIGNUM_INT_BITS_BITS-1)); i != 0; i >>= 1) { - BignumInt shifted_word = hiword >> i; - BignumInt indicator = - (BignumInt)(-shifted_word) >> (BIGNUM_INT_BITS-1); - hiword ^= (shifted_word ^ hiword ) & -indicator; - hibit_index += i & -(size_t)indicator; - } - - /* - * Put together the result. - */ - return (hiword_index << BIGNUM_INT_BITS_BITS) + hibit_index + 1; -} - -/* - * Shared code between the hex and decimal output functions to get rid - * of leading zeroes on the output string. The idea is that we wrote - * out a fixed number of digits and a trailing \0 byte into 'buf', and - * now we want to shift it all left so that the first nonzero digit - * moves to buf[0] (or, if there are no nonzero digits at all, we move - * up by 'maxtrim', so that we return 0 as "0" instead of ""). - */ -static void trim_leading_zeroes(char *buf, size_t bufsize, size_t maxtrim) -{ - size_t trim = maxtrim; - - /* - * Look for the first character not equal to '0', to find the - * shift count. - */ - if (trim > 0) { - for (size_t pos = trim; pos-- > 0 ;) { - uint8_t diff = buf[pos] ^ '0'; - size_t mask = -((((size_t)diff) - 1) >> (SIZE_T_BITS - 1)); - trim ^= (trim ^ pos) & ~mask; - } - } - - /* - * Now do the shift, in log n passes each of which does a - * conditional shift by 2^i bytes if bit i is set in the shift - * count. - */ - uint8_t *ubuf = (uint8_t *)buf; - for (size_t logd = 0; bufsize >> logd; logd++) { - uint8_t mask = -(uint8_t)((trim >> logd) & 1); - size_t d = (size_t)1 << logd; - for (size_t i = 0; i+d < bufsize; i++) { - uint8_t diff = mask & (ubuf[i] ^ ubuf[i+d]); - ubuf[i] ^= diff; - ubuf[i+d] ^= diff; - } - } -} - -/* - * Binary to decimal conversion. Our strategy here is to extract each - * decimal digit by finding the input number's residue mod 10, then - * subtract that off to give an exact multiple of 10, which then means - * you can safely divide by 10 by means of shifting right one bit and - * then multiplying by the inverse of 5 mod 2^n. - */ -char *mp_get_decimal(mp_int *x_orig) -{ - mp_int *x = mp_copy(x_orig), *y = mp_make_sized(x->nw); - - /* - * The inverse of 5 mod 2^lots is 0xccccccccccccccccccccd, for an - * appropriate number of 'c's. Manually construct an integer the - * right size. - */ - mp_int *inv5 = mp_make_sized(x->nw); - assert(BIGNUM_INT_BITS % 8 == 0); - for (size_t i = 0; i < inv5->nw; i++) - inv5->w[i] = BIGNUM_INT_MASK / 5 * 4; - inv5->w[0]++; - - /* - * 146/485 is an upper bound (and also a continued-fraction - * convergent) of log10(2), so this is a conservative estimate of - * the number of decimal digits needed to store a value that fits - * in this many binary bits. - */ - assert(x->nw < (~(size_t)1) / (146 * BIGNUM_INT_BITS)); - size_t bufsize = size_t_max(x->nw * (146 * BIGNUM_INT_BITS) / 485, 1) + 2; - char *outbuf = snewn(bufsize, char); - outbuf[bufsize - 1] = '\0'; - - /* - * Loop over the number generating digits from the least - * significant upwards, so that we write to outbuf in reverse - * order. - */ - for (size_t pos = bufsize - 1; pos-- > 0 ;) { - /* - * Find the current residue mod 10. We do this by first - * summing the bytes of the number, with all but the lowest - * one multiplied by 6 (because 256^i == 6 mod 10 for all - * i>0). That gives us a single word congruent mod 10 to the - * input number, and then we reduce it further by manual - * multiplication and shifting, just in case the compiler - * target implements the C division operator in a way that has - * input-dependent timing. - */ - uint32_t low_digit = 0, maxval = 0, mult = 1; - for (size_t i = 0; i < x->nw; i++) { - for (unsigned j = 0; j < BIGNUM_INT_BYTES; j++) { - low_digit += mult * (0xFF & (x->w[i] >> (8*j))); - maxval += mult * 0xFF; - mult = 6; - } - /* - * For _really_ big numbers, prevent overflow of t by - * periodically folding the top half of the accumulator - * into the bottom half, using the same rule 'multiply by - * 6 when shifting down by one or more whole bytes'. - */ - if (maxval > UINT32_MAX - (6 * 0xFF * BIGNUM_INT_BYTES)) { - low_digit = (low_digit & 0xFFFF) + 6 * (low_digit >> 16); - maxval = (maxval & 0xFFFF) + 6 * (maxval >> 16); - } - } - - /* - * Final reduction of low_digit. We multiply by 2^32 / 10 - * (that's the constant 0x19999999) to get a 64-bit value - * whose top 32 bits are the approximate quotient - * low_digit/10; then we subtract off 10 times that; and - * finally we do one last trial subtraction of 10 by adding 6 - * (which sets bit 4 if the number was just over 10) and then - * testing bit 4. - */ - low_digit -= 10 * ((0x19999999ULL * low_digit) >> 32); - low_digit -= 10 * ((low_digit + 6) >> 4); - - assert(low_digit < 10); /* make sure we did reduce fully */ - outbuf[pos] = '0' + low_digit; - - /* - * Now subtract off that digit, divide by 2 (using a right - * shift) and by 5 (using the modular inverse), to get the - * next output digit into the units position. - */ - mp_sub_integer_into(x, x, low_digit); - mp_rshift_fixed_into(y, x, 1); - mp_mul_into(x, y, inv5); - } - - mp_free(x); - mp_free(y); - mp_free(inv5); - - trim_leading_zeroes(outbuf, bufsize, bufsize - 2); - return outbuf; -} - -/* - * Binary to hex conversion. Reasonably simple (only a spot of bit - * twiddling to choose whether to output a digit or a letter for each - * nibble). - */ -static char *mp_get_hex_internal(mp_int *x, uint8_t letter_offset) -{ - size_t nibbles = x->nw * BIGNUM_INT_BYTES * 2; - size_t bufsize = nibbles + 1; - char *outbuf = snewn(bufsize, char); - outbuf[nibbles] = '\0'; - - for (size_t nibble = 0; nibble < nibbles; nibble++) { - size_t word_idx = nibble / (BIGNUM_INT_BYTES*2); - size_t nibble_within_word = nibble % (BIGNUM_INT_BYTES*2); - uint8_t digitval = 0xF & (x->w[word_idx] >> (nibble_within_word * 4)); - - uint8_t mask = -((digitval + 6) >> 4); - char digit = digitval + '0' + (letter_offset & mask); - outbuf[nibbles-1 - nibble] = digit; - } - - trim_leading_zeroes(outbuf, bufsize, nibbles - 1); - return outbuf; -} - -char *mp_get_hex(mp_int *x) -{ - return mp_get_hex_internal(x, 'a' - ('0'+10)); -} - -char *mp_get_hex_uppercase(mp_int *x) -{ - return mp_get_hex_internal(x, 'A' - ('0'+10)); -} - -/* - * Routines for reading and writing the SSH-1 and SSH-2 wire formats - * for multiprecision integers, declared in marshal.h. - * - * These can't avoid having control flow dependent on the true bit - * size of the number, because the wire format requires the number of - * output bytes to depend on that. - */ -void BinarySink_put_mp_ssh1(BinarySink *bs, mp_int *x) -{ - size_t bits = mp_get_nbits(x); - size_t bytes = (bits + 7) / 8; - - assert(bits < 0x10000); - put_uint16(bs, bits); - for (size_t i = bytes; i-- > 0 ;) - put_byte(bs, mp_get_byte(x, i)); -} - -void BinarySink_put_mp_ssh2(BinarySink *bs, mp_int *x) -{ - size_t bytes = (mp_get_nbits(x) + 8) / 8; - - put_uint32(bs, bytes); - for (size_t i = bytes; i-- > 0 ;) - put_byte(bs, mp_get_byte(x, i)); -} - -mp_int *BinarySource_get_mp_ssh1(BinarySource *src) -{ - unsigned bitc = get_uint16(src); - ptrlen bytes = get_data(src, (bitc + 7) / 8); - if (get_err(src)) { - return mp_from_integer(0); - } else { - mp_int *toret = mp_from_bytes_be(bytes); - /* SSH-1.5 spec says that it's OK for the prefix uint16 to be - * _greater_ than the actual number of bits */ - if (mp_get_nbits(toret) > bitc) { - src->err = BSE_INVALID; - mp_free(toret); - toret = mp_from_integer(0); - } - return toret; - } -} - -mp_int *BinarySource_get_mp_ssh2(BinarySource *src) -{ - ptrlen bytes = get_string(src); - if (get_err(src)) { - return mp_from_integer(0); - } else { - const unsigned char *p = bytes.ptr; - if ((bytes.len > 0 && - ((p[0] & 0x80) || - (p[0] == 0 && (bytes.len <= 1 || !(p[1] & 0x80)))))) { - src->err = BSE_INVALID; - return mp_from_integer(0); - } - return mp_from_bytes_be(bytes); - } -} - -/* - * Make an mp_int structure whose words array aliases a subinterval of - * some other mp_int. This makes it easy to read or write just the low - * or high words of a number, e.g. to add a number starting from a - * high bit position, or to reduce mod 2^{n*BIGNUM_INT_BITS}. - * - * The convention throughout this code is that when we store an mp_int - * directly by value, we always expect it to be an alias of some kind, - * so its words array won't ever need freeing. Whereas an 'mp_int *' - * has an owner, who knows whether it needs freeing or whether it was - * created by address-taking an alias. - */ -static mp_int mp_make_alias(mp_int *in, size_t offset, size_t len) -{ - /* - * Bounds-check the offset and length so that we always return - * something valid, even if it's not necessarily the length the - * caller asked for. - */ - if (offset > in->nw) - offset = in->nw; - if (len > in->nw - offset) - len = in->nw - offset; - - mp_int toret; - toret.nw = len; - toret.w = in->w + offset; - return toret; -} - -/* - * A special case of mp_make_alias: in some cases we preallocate a - * large mp_int to use as scratch space (to avoid pointless - * malloc/free churn in recursive or iterative work). - * - * mp_alloc_from_scratch creates an alias of size 'len' to part of - * 'pool', and adjusts 'pool' itself so that further allocations won't - * overwrite that space. - * - * There's no free function to go with this. Typically you just copy - * the pool mp_int by value, allocate from the copy, and when you're - * done with those allocations, throw the copy away and go back to the - * original value of pool. (A mark/release system.) - */ -static mp_int mp_alloc_from_scratch(mp_int *pool, size_t len) -{ - assert(len <= pool->nw); - mp_int toret = mp_make_alias(pool, 0, len); - *pool = mp_make_alias(pool, len, pool->nw); - return toret; -} - -/* - * Internal component common to lots of assorted add/subtract code. - * Reads words from a,b; writes into w_out (which might be NULL if the - * output isn't even needed). Takes an input carry flag in 'carry', - * and returns the output carry. Each word read from b is ANDed with - * b_and and then XORed with b_xor. - * - * So you can implement addition by setting b_and to all 1s and b_xor - * to 0; you can subtract by making b_xor all 1s too (effectively - * bit-flipping b) and also passing 1 as the input carry (to turn - * one's complement into two's complement). And you can do conditional - * add/subtract by choosing b_and to be all 1s or all 0s based on a - * condition, because the value of b will be totally ignored if b_and - * == 0. - */ -static BignumCarry mp_add_masked_into( - BignumInt *w_out, size_t rw, mp_int *a, mp_int *b, - BignumInt b_and, BignumInt b_xor, BignumCarry carry) -{ - for (size_t i = 0; i < rw; i++) { - BignumInt aword = mp_word(a, i), bword = mp_word(b, i), out; - bword = (bword & b_and) ^ b_xor; - BignumADC(out, carry, aword, bword, carry); - if (w_out) - w_out[i] = out; - } - return carry; -} - -/* - * Like the public mp_add_into except that it returns the output carry. - */ -static inline BignumCarry mp_add_into_internal(mp_int *r, mp_int *a, mp_int *b) -{ - return mp_add_masked_into(r->w, r->nw, a, b, ~(BignumInt)0, 0, 0); -} - -void mp_add_into(mp_int *r, mp_int *a, mp_int *b) -{ - mp_add_into_internal(r, a, b); -} - -void mp_sub_into(mp_int *r, mp_int *a, mp_int *b) -{ - mp_add_masked_into(r->w, r->nw, a, b, ~(BignumInt)0, ~(BignumInt)0, 1); -} - -void mp_and_into(mp_int *r, mp_int *a, mp_int *b) -{ - for (size_t i = 0; i < r->nw; i++) { - BignumInt aword = mp_word(a, i), bword = mp_word(b, i); - r->w[i] = aword & bword; - } -} - -void mp_or_into(mp_int *r, mp_int *a, mp_int *b) -{ - for (size_t i = 0; i < r->nw; i++) { - BignumInt aword = mp_word(a, i), bword = mp_word(b, i); - r->w[i] = aword | bword; - } -} - -void mp_xor_into(mp_int *r, mp_int *a, mp_int *b) -{ - for (size_t i = 0; i < r->nw; i++) { - BignumInt aword = mp_word(a, i), bword = mp_word(b, i); - r->w[i] = aword ^ bword; - } -} - -void mp_bic_into(mp_int *r, mp_int *a, mp_int *b) -{ - for (size_t i = 0; i < r->nw; i++) { - BignumInt aword = mp_word(a, i), bword = mp_word(b, i); - r->w[i] = aword & ~bword; - } -} - -static void mp_cond_negate(mp_int *r, mp_int *x, unsigned yes) -{ - BignumCarry carry = yes; - BignumInt flip = -(BignumInt)yes; - for (size_t i = 0; i < r->nw; i++) { - BignumInt xword = mp_word(x, i); - xword ^= flip; - BignumADC(r->w[i], carry, 0, xword, carry); - } -} - -/* - * Similar to mp_add_masked_into, but takes a C integer instead of an - * mp_int as the masked operand. - */ -static BignumCarry mp_add_masked_integer_into( - BignumInt *w_out, size_t rw, mp_int *a, uintmax_t b, - BignumInt b_and, BignumInt b_xor, BignumCarry carry) -{ - for (size_t i = 0; i < rw; i++) { - BignumInt aword = mp_word(a, i); - size_t shift = i * BIGNUM_INT_BITS; - BignumInt bword = shift < BIGNUM_INT_BYTES ? b >> shift : 0; - BignumInt out; - bword = (bword ^ b_xor) & b_and; - BignumADC(out, carry, aword, bword, carry); - if (w_out) - w_out[i] = out; - } - return carry; -} - -void mp_add_integer_into(mp_int *r, mp_int *a, uintmax_t n) -{ - mp_add_masked_integer_into(r->w, r->nw, a, n, ~(BignumInt)0, 0, 0); -} - -void mp_sub_integer_into(mp_int *r, mp_int *a, uintmax_t n) -{ - mp_add_masked_integer_into(r->w, r->nw, a, n, - ~(BignumInt)0, ~(BignumInt)0, 1); -} - -/* - * Sets r to a + n << (word_index * BIGNUM_INT_BITS), treating - * word_index as secret data. - */ -static void mp_add_integer_into_shifted_by_words( - mp_int *r, mp_int *a, uintmax_t n, size_t word_index) -{ - unsigned indicator = 0; - BignumCarry carry = 0; - - for (size_t i = 0; i < r->nw; i++) { - /* indicator becomes 1 when we reach the index that the least - * significant bits of n want to be placed at, and it stays 1 - * thereafter. */ - indicator |= 1 ^ normalise_to_1(i ^ word_index); - - /* If indicator is 1, we add the low bits of n into r, and - * shift n down. If it's 0, we add zero bits into r, and - * leave n alone. */ - BignumInt bword = n & -(BignumInt)indicator; - uintmax_t new_n = (BIGNUM_INT_BITS < 64 ? n >> BIGNUM_INT_BITS : 0); - n ^= (n ^ new_n) & -(uintmax_t)indicator; - - BignumInt aword = mp_word(a, i); - BignumInt out; - BignumADC(out, carry, aword, bword, carry); - r->w[i] = out; - } -} - -void mp_mul_integer_into(mp_int *r, mp_int *a, uint16_t n) -{ - BignumInt carry = 0, mult = n; - for (size_t i = 0; i < r->nw; i++) { - BignumInt aword = mp_word(a, i); - BignumMULADD(carry, r->w[i], aword, mult, carry); - } - assert(!carry); -} - -void mp_cond_add_into(mp_int *r, mp_int *a, mp_int *b, unsigned yes) -{ - BignumInt mask = -(BignumInt)(yes & 1); - mp_add_masked_into(r->w, r->nw, a, b, mask, 0, 0); -} - -void mp_cond_sub_into(mp_int *r, mp_int *a, mp_int *b, unsigned yes) -{ - BignumInt mask = -(BignumInt)(yes & 1); - mp_add_masked_into(r->w, r->nw, a, b, mask, mask, 1 & mask); -} - -/* - * Ordered comparison between unsigned numbers is done by subtracting - * one from the other and looking at the output carry. - */ -unsigned mp_cmp_hs(mp_int *a, mp_int *b) -{ - size_t rw = size_t_max(a->nw, b->nw); - return mp_add_masked_into(NULL, rw, a, b, ~(BignumInt)0, ~(BignumInt)0, 1); -} - -unsigned mp_hs_integer(mp_int *x, uintmax_t n) -{ - BignumInt carry = 1; - for (size_t i = 0; i < x->nw; i++) { - size_t shift = i * BIGNUM_INT_BITS; - BignumInt nword = shift < CHAR_BIT*sizeof(n) ? n >> shift : 0; - BignumInt dummy_out; - BignumADC(dummy_out, carry, x->w[i], ~nword, carry); - (void)dummy_out; - } - return carry; -} - -/* - * Equality comparison is done by bitwise XOR of the input numbers, - * ORing together all the output words, and normalising the result - * using our careful normalise_to_1 helper function. - */ -unsigned mp_cmp_eq(mp_int *a, mp_int *b) -{ - BignumInt diff = 0; - for (size_t i = 0, limit = size_t_max(a->nw, b->nw); i < limit; i++) - diff |= mp_word(a, i) ^ mp_word(b, i); - return 1 ^ normalise_to_1(diff); /* return 1 if diff _is_ zero */ -} - -unsigned mp_eq_integer(mp_int *x, uintmax_t n) -{ - BignumInt diff = 0; - for (size_t i = 0; i < x->nw; i++) { - size_t shift = i * BIGNUM_INT_BITS; - BignumInt nword = shift < CHAR_BIT*sizeof(n) ? n >> shift : 0; - diff |= x->w[i] ^ nword; - } - return 1 ^ normalise_to_1(diff); /* return 1 if diff _is_ zero */ -} - -void mp_neg_into(mp_int *r, mp_int *a) -{ - mp_int zero; - zero.nw = 0; - mp_sub_into(r, &zero, a); -} - -mp_int *mp_add(mp_int *x, mp_int *y) -{ - mp_int *r = mp_make_sized(size_t_max(x->nw, y->nw) + 1); - mp_add_into(r, x, y); - return r; -} - -mp_int *mp_sub(mp_int *x, mp_int *y) -{ - mp_int *r = mp_make_sized(size_t_max(x->nw, y->nw)); - mp_sub_into(r, x, y); - return r; -} - -mp_int *mp_neg(mp_int *a) -{ - mp_int *r = mp_make_sized(a->nw); - mp_neg_into(r, a); - return r; -} - -/* - * Internal routine: multiply and accumulate in the trivial O(N^2) - * way. Sets r <- r + a*b. - */ -static void mp_mul_add_simple(mp_int *r, mp_int *a, mp_int *b) -{ - BignumInt *aend = a->w + a->nw, *bend = b->w + b->nw, *rend = r->w + r->nw; - - for (BignumInt *ap = a->w, *rp = r->w; - ap < aend && rp < rend; ap++, rp++) { - - BignumInt adata = *ap, carry = 0, *rq = rp; - - for (BignumInt *bp = b->w; bp < bend && rq < rend; bp++, rq++) { - BignumInt bdata = bp < bend ? *bp : 0; - BignumMULADD2(carry, *rq, adata, bdata, *rq, carry); - } - - for (; rq < rend; rq++) - BignumADC(*rq, carry, carry, *rq, 0); - } -} - -#ifndef KARATSUBA_THRESHOLD /* allow redefinition via -D for testing */ -#define KARATSUBA_THRESHOLD 24 -#endif - -static inline size_t mp_mul_scratchspace_unary(size_t n) -{ - /* - * Simplistic and overcautious bound on the amount of scratch - * space that the recursive multiply function will need. - * - * The rationale is: on the main Karatsuba branch of - * mp_mul_internal, which is the most space-intensive one, we - * allocate space for (a0+a1) and (b0+b1) (each just over half the - * input length n) and their product (the sum of those sizes, i.e. - * just over n itself). Then in order to actually compute the - * product, we do a recursive multiplication of size just over n. - * - * If all those 'just over' weren't there, and everything was - * _exactly_ half the length, you'd get the amount of space for a - * size-n multiply defined by the recurrence M(n) = 2n + M(n/2), - * which is satisfied by M(n) = 4n. But instead it's (2n plus a - * word or two) and M(n/2 plus a word or two). On the assumption - * that there's still some constant k such that M(n) <= kn, this - * gives us kn = 2n + w + k(n/2 + w), where w is a small constant - * (one or two words). That simplifies to kn/2 = 2n + (k+1)w, and - * since we don't even _start_ needing scratch space until n is at - * least 50, we can bound 2n + (k+1)w above by 3n, giving k=6. - * - * So I claim that 6n words of scratch space will suffice, and I - * check that by assertion at every stage of the recursion. - */ - return n * 6; -} - -static size_t mp_mul_scratchspace(size_t rw, size_t aw, size_t bw) -{ - size_t inlen = size_t_min(rw, size_t_max(aw, bw)); - return mp_mul_scratchspace_unary(inlen); -} - -static void mp_mul_internal(mp_int *r, mp_int *a, mp_int *b, mp_int scratch) -{ - size_t inlen = size_t_min(r->nw, size_t_max(a->nw, b->nw)); - assert(scratch.nw >= mp_mul_scratchspace_unary(inlen)); - - mp_clear(r); - - if (inlen < KARATSUBA_THRESHOLD || a->nw == 0 || b->nw == 0) { - /* - * The input numbers are too small to bother optimising. Go - * straight to the simple primitive approach. - */ - mp_mul_add_simple(r, a, b); - return; - } - - /* - * Karatsuba divide-and-conquer algorithm. We cut each input in - * half, so that it's expressed as two big 'digits' in a giant - * base D: - * - * a = a_1 D + a_0 - * b = b_1 D + b_0 - * - * Then the product is of course - * - * ab = a_1 b_1 D^2 + (a_1 b_0 + a_0 b_1) D + a_0 b_0 - * - * and we compute the three coefficients by recursively calling - * ourself to do half-length multiplications. - * - * The clever bit that makes this worth doing is that we only need - * _one_ half-length multiplication for the central coefficient - * rather than the two that it obviouly looks like, because we can - * use a single multiplication to compute - * - * (a_1 + a_0) (b_1 + b_0) = a_1 b_1 + a_1 b_0 + a_0 b_1 + a_0 b_0 - * - * and then we subtract the other two coefficients (a_1 b_1 and - * a_0 b_0) which we were computing anyway. - * - * Hence we get to multiply two numbers of length N in about three - * times as much work as it takes to multiply numbers of length - * N/2, which is obviously better than the four times as much work - * it would take if we just did a long conventional multiply. - */ - - /* Break up the input as botlen + toplen, with botlen >= toplen. - * The 'base' D is equal to 2^{botlen * BIGNUM_INT_BITS}. */ - size_t toplen = inlen / 2; - size_t botlen = inlen - toplen; - - /* Alias bignums that address the two halves of a,b, and useful - * pieces of r. */ - mp_int a0 = mp_make_alias(a, 0, botlen); - mp_int b0 = mp_make_alias(b, 0, botlen); - mp_int a1 = mp_make_alias(a, botlen, toplen); - mp_int b1 = mp_make_alias(b, botlen, toplen); - mp_int r0 = mp_make_alias(r, 0, botlen*2); - mp_int r1 = mp_make_alias(r, botlen, r->nw); - mp_int r2 = mp_make_alias(r, botlen*2, r->nw); - - /* Recurse to compute a0*b0 and a1*b1, in their correct positions - * in the output bignum. They can't overlap. */ - mp_mul_internal(&r0, &a0, &b0, scratch); - mp_mul_internal(&r2, &a1, &b1, scratch); - - if (r->nw < inlen*2) { - /* - * The output buffer isn't large enough to require the whole - * product, so some of a1*b1 won't have been stored. In that - * case we won't try to do the full Karatsuba optimisation; - * we'll just recurse again to compute a0*b1 and a1*b0 - or at - * least as much of them as the output buffer size requires - - * and add each one in. - */ - mp_int s = mp_alloc_from_scratch( - &scratch, size_t_min(botlen+toplen, r1.nw)); - - mp_mul_internal(&s, &a0, &b1, scratch); - mp_add_into(&r1, &r1, &s); - mp_mul_internal(&s, &a1, &b0, scratch); - mp_add_into(&r1, &r1, &s); - return; - } - - /* a0+a1 and b0+b1 */ - mp_int asum = mp_alloc_from_scratch(&scratch, botlen+1); - mp_int bsum = mp_alloc_from_scratch(&scratch, botlen+1); - mp_add_into(&asum, &a0, &a1); - mp_add_into(&bsum, &b0, &b1); - - /* Their product */ - mp_int product = mp_alloc_from_scratch(&scratch, botlen*2+1); - mp_mul_internal(&product, &asum, &bsum, scratch); - - /* Subtract off the outer terms we already have */ - mp_sub_into(&product, &product, &r0); - mp_sub_into(&product, &product, &r2); - - /* And add it in with the right offset. */ - mp_add_into(&r1, &r1, &product); -} - -void mp_mul_into(mp_int *r, mp_int *a, mp_int *b) -{ - mp_int *scratch = mp_make_sized(mp_mul_scratchspace(r->nw, a->nw, b->nw)); - mp_mul_internal(r, a, b, *scratch); - mp_free(scratch); -} - -mp_int *mp_mul(mp_int *x, mp_int *y) -{ - mp_int *r = mp_make_sized(x->nw + y->nw); - mp_mul_into(r, x, y); - return r; -} - -void mp_lshift_fixed_into(mp_int *r, mp_int *a, size_t bits) -{ - size_t words = bits / BIGNUM_INT_BITS; - size_t bitoff = bits % BIGNUM_INT_BITS; - - for (size_t i = r->nw; i-- > 0 ;) { - if (i < words) { - r->w[i] = 0; - } else { - r->w[i] = mp_word(a, i - words); - if (bitoff != 0) { - r->w[i] <<= bitoff; - if (i > words) - r->w[i] |= mp_word(a, i - words - 1) >> - (BIGNUM_INT_BITS - bitoff); - } - } - } -} - -void mp_rshift_fixed_into(mp_int *r, mp_int *a, size_t bits) -{ - size_t words = bits / BIGNUM_INT_BITS; - size_t bitoff = bits % BIGNUM_INT_BITS; - - for (size_t i = 0; i < r->nw; i++) { - r->w[i] = mp_word(a, i + words); - if (bitoff != 0) { - r->w[i] >>= bitoff; - r->w[i] |= mp_word(a, i + words + 1) << (BIGNUM_INT_BITS - bitoff); - } - } -} - -mp_int *mp_rshift_fixed(mp_int *x, size_t bits) -{ - size_t words = bits / BIGNUM_INT_BITS; - size_t nw = x->nw - size_t_min(x->nw, words); - mp_int *r = mp_make_sized(size_t_max(nw, 1)); - mp_rshift_fixed_into(r, x, bits); - return r; -} - -/* - * Safe right shift is done using the same technique as - * trim_leading_zeroes above: you make an n-word left shift by - * composing an appropriate subset of power-of-2-sized shifts, so it - * takes log_2(n) loop iterations each of which does a different shift - * by a power of 2 words, using the usual bit twiddling to make the - * whole shift conditional on the appropriate bit of n. - */ -mp_int *mp_rshift_safe(mp_int *x, size_t bits) -{ - size_t wordshift = bits / BIGNUM_INT_BITS; - size_t bitshift = bits % BIGNUM_INT_BITS; - - mp_int *r = mp_copy(x); - - unsigned clear = (r->nw - wordshift) >> (CHAR_BIT * sizeof(size_t) - 1); - mp_cond_clear(r, clear); - - for (unsigned bit = 0; r->nw >> bit; bit++) { - size_t word_offset = 1 << bit; - BignumInt mask = -(BignumInt)((wordshift >> bit) & 1); - for (size_t i = 0; i < r->nw; i++) { - BignumInt w = mp_word(r, i + word_offset); - r->w[i] ^= (r->w[i] ^ w) & mask; - } - } - - /* - * That's done the shifting by words; now we do the shifting by - * bits. - */ - for (unsigned bit = 0; bit < BIGNUM_INT_BITS_BITS; bit++) { - unsigned shift = 1 << bit, upshift = BIGNUM_INT_BITS - shift; - BignumInt mask = -(BignumInt)((bitshift >> bit) & 1); - for (size_t i = 0; i < r->nw; i++) { - BignumInt w = ((r->w[i] >> shift) | (mp_word(r, i+1) << upshift)); - r->w[i] ^= (r->w[i] ^ w) & mask; - } - } - - return r; -} - -void mp_reduce_mod_2to(mp_int *x, size_t p) -{ - size_t word = p / BIGNUM_INT_BITS; - size_t mask = ((size_t)1 << (p % BIGNUM_INT_BITS)) - 1; - for (; word < x->nw; word++) { - x->w[word] &= mask; - mask = 0; - } -} - -/* - * Inverse mod 2^n is computed by an iterative technique which doubles - * the number of bits at each step. - */ -mp_int *mp_invert_mod_2to(mp_int *x, size_t p) -{ - /* Input checks: x must be coprime to the modulus, i.e. odd, and p - * can't be zero */ - assert(x->nw > 0); - assert(x->w[0] & 1); - assert(p > 0); - - size_t rw = (p + BIGNUM_INT_BITS - 1) / BIGNUM_INT_BITS; - rw = size_t_max(rw, 1); - mp_int *r = mp_make_sized(rw); - - size_t mul_scratchsize = mp_mul_scratchspace(2*rw, rw, rw); - mp_int *scratch_orig = mp_make_sized(6 * rw + mul_scratchsize); - mp_int scratch_per_iter = *scratch_orig; - mp_int mul_scratch = mp_alloc_from_scratch( - &scratch_per_iter, mul_scratchsize); - - r->w[0] = 1; - - for (size_t b = 1; b < p; b <<= 1) { - /* - * In each step of this iteration, we have the inverse of x - * mod 2^b, and we want the inverse of x mod 2^{2b}. - * - * Write B = 2^b for convenience, so we want x^{-1} mod B^2. - * Let x = x_0 + B x_1 + k B^2, with 0 <= x_0,x_1 < B. - * - * We want to find r_0 and r_1 such that - * (r_1 B + r_0) (x_1 B + x_0) == 1 (mod B^2) - * - * To begin with, we know r_0 must be the inverse mod B of - * x_0, i.e. of x, i.e. it is the inverse we computed in the - * previous iteration. So now all we need is r_1. - * - * Multiplying out, neglecting multiples of B^2, and writing - * x_0 r_0 = K B + 1, we have - * - * r_1 x_0 B + r_0 x_1 B + K B == 0 (mod B^2) - * => r_1 x_0 B == - r_0 x_1 B - K B (mod B^2) - * => r_1 x_0 == - r_0 x_1 - K (mod B) - * => r_1 == r_0 (- r_0 x_1 - K) (mod B) - * - * (the last step because we multiply through by the inverse - * of x_0, which we already know is r_0). - */ - - mp_int scratch_this_iter = scratch_per_iter; - size_t Bw = (b + BIGNUM_INT_BITS - 1) / BIGNUM_INT_BITS; - size_t B2w = (2*b + BIGNUM_INT_BITS - 1) / BIGNUM_INT_BITS; - - /* Start by finding K: multiply x_0 by r_0, and shift down. */ - mp_int x0 = mp_alloc_from_scratch(&scratch_this_iter, Bw); - mp_copy_into(&x0, x); - mp_reduce_mod_2to(&x0, b); - mp_int r0 = mp_make_alias(r, 0, Bw); - mp_int Kshift = mp_alloc_from_scratch(&scratch_this_iter, B2w); - mp_mul_internal(&Kshift, &x0, &r0, mul_scratch); - mp_int K = mp_alloc_from_scratch(&scratch_this_iter, Bw); - mp_rshift_fixed_into(&K, &Kshift, b); - - /* Now compute the product r_0 x_1, reusing the space of Kshift. */ - mp_int x1 = mp_alloc_from_scratch(&scratch_this_iter, Bw); - mp_rshift_fixed_into(&x1, x, b); - mp_reduce_mod_2to(&x1, b); - mp_int r0x1 = mp_make_alias(&Kshift, 0, Bw); - mp_mul_internal(&r0x1, &r0, &x1, mul_scratch); - - /* Add K to that. */ - mp_add_into(&r0x1, &r0x1, &K); - - /* Negate it. */ - mp_neg_into(&r0x1, &r0x1); - - /* Multiply by r_0. */ - mp_int r1 = mp_alloc_from_scratch(&scratch_this_iter, Bw); - mp_mul_internal(&r1, &r0, &r0x1, mul_scratch); - mp_reduce_mod_2to(&r1, b); - - /* That's our r_1, so add it on to r_0 to get the full inverse - * output from this iteration. */ - mp_lshift_fixed_into(&K, &r1, (b % BIGNUM_INT_BITS)); - size_t Bpos = b / BIGNUM_INT_BITS; - mp_int r1_position = mp_make_alias(r, Bpos, B2w-Bpos); - mp_add_into(&r1_position, &r1_position, &K); - } - - /* Finally, reduce mod the precise desired number of bits. */ - mp_reduce_mod_2to(r, p); - - mp_free(scratch_orig); - return r; -} - -static size_t monty_scratch_size(MontyContext *mc) -{ - return 3*mc->rw + mc->pw + mp_mul_scratchspace(mc->pw, mc->rw, mc->rw); -} - -MontyContext *monty_new(mp_int *modulus) -{ - MontyContext *mc = snew(MontyContext); - - mc->rw = modulus->nw; - mc->rbits = mc->rw * BIGNUM_INT_BITS; - mc->pw = mc->rw * 2 + 1; - - mc->m = mp_copy(modulus); - - mc->minus_minv_mod_r = mp_invert_mod_2to(mc->m, mc->rbits); - mp_neg_into(mc->minus_minv_mod_r, mc->minus_minv_mod_r); - - mp_int *r = mp_make_sized(mc->rw + 1); - r->w[mc->rw] = 1; - mc->powers_of_r_mod_m[0] = mp_mod(r, mc->m); - mp_free(r); - - for (size_t j = 1; j < lenof(mc->powers_of_r_mod_m); j++) - mc->powers_of_r_mod_m[j] = mp_modmul( - mc->powers_of_r_mod_m[0], mc->powers_of_r_mod_m[j-1], mc->m); - - mc->scratch = mp_make_sized(monty_scratch_size(mc)); - - return mc; -} - -void monty_free(MontyContext *mc) -{ - mp_free(mc->m); - for (size_t j = 0; j < 3; j++) - mp_free(mc->powers_of_r_mod_m[j]); - mp_free(mc->minus_minv_mod_r); - mp_free(mc->scratch); - smemclr(mc, sizeof(*mc)); - sfree(mc); -} - -/* - * The main Montgomery reduction step. - */ -static mp_int monty_reduce_internal(MontyContext *mc, mp_int *x, mp_int scratch) -{ - /* - * The trick with Montgomery reduction is that on the one hand we - * want to reduce the size of the input by a factor of about r, - * and on the other hand, the two numbers we just multiplied were - * both stored with an extra factor of r multiplied in. So we - * computed ar*br = ab r^2, but we want to return abr, so we need - * to divide by r - and if we can do that by _actually dividing_ - * by r then this also reduces the size of the number. - * - * But we can only do that if the number we're dividing by r is a - * multiple of r. So first we must add an adjustment to it which - * clears its bottom 'rbits' bits. That adjustment must be a - * multiple of m in order to leave the residue mod n unchanged, so - * the question is, what multiple of m can we add to x to make it - * congruent to 0 mod r? And the answer is, x * (-m)^{-1} mod r. - */ - - /* x mod r */ - mp_int x_lo = mp_make_alias(x, 0, mc->rbits); - - /* x * (-m)^{-1}, i.e. the number we want to multiply by m */ - mp_int k = mp_alloc_from_scratch(&scratch, mc->rw); - mp_mul_internal(&k, &x_lo, mc->minus_minv_mod_r, scratch); - - /* m times that, i.e. the number we want to add to x */ - mp_int mk = mp_alloc_from_scratch(&scratch, mc->pw); - mp_mul_internal(&mk, mc->m, &k, scratch); - - /* Add it to x */ - mp_add_into(&mk, x, &mk); - - /* Reduce mod r, by simply making an alias to the upper words of x */ - mp_int toret = mp_make_alias(&mk, mc->rw, mk.nw - mc->rw); - - /* - * We'll generally be doing this after a multiplication of two - * fully reduced values. So our input could be anything up to m^2, - * and then we added up to rm to it. Hence, the maximum value is - * rm+m^2, and after dividing by r, that becomes r + m(m/r) < 2r. - * So a single trial-subtraction will finish reducing to the - * interval [0,m). - */ - mp_cond_sub_into(&toret, &toret, mc->m, mp_cmp_hs(&toret, mc->m)); - return toret; -} - -void monty_mul_into(MontyContext *mc, mp_int *r, mp_int *x, mp_int *y) -{ - assert(x->nw <= mc->rw); - assert(y->nw <= mc->rw); - - mp_int scratch = *mc->scratch; - mp_int tmp = mp_alloc_from_scratch(&scratch, 2*mc->rw); - mp_mul_into(&tmp, x, y); - mp_int reduced = monty_reduce_internal(mc, &tmp, scratch); - mp_copy_into(r, &reduced); - mp_clear(mc->scratch); -} - -mp_int *monty_mul(MontyContext *mc, mp_int *x, mp_int *y) -{ - mp_int *toret = mp_make_sized(mc->rw); - monty_mul_into(mc, toret, x, y); - return toret; -} - -mp_int *monty_modulus(MontyContext *mc) -{ - return mc->m; -} - -mp_int *monty_identity(MontyContext *mc) -{ - return mc->powers_of_r_mod_m[0]; -} - -mp_int *monty_invert(MontyContext *mc, mp_int *x) -{ - /* Given xr, we want to return x^{-1}r = (xr)^{-1} r^2 = - * monty_reduce((xr)^{-1} r^3) */ - mp_int *tmp = mp_invert(x, mc->m); - mp_int *toret = monty_mul(mc, tmp, mc->powers_of_r_mod_m[2]); - mp_free(tmp); - return toret; -} - -/* - * Importing a number into Montgomery representation involves - * multiplying it by r and reducing mod m. We use the general-purpose - * mp_modmul for this, in case the input number is out of range. - */ -mp_int *monty_import(MontyContext *mc, mp_int *x) -{ - return mp_modmul(x, mc->powers_of_r_mod_m[0], mc->m); -} - -void monty_import_into(MontyContext *mc, mp_int *r, mp_int *x) -{ - mp_int *imported = monty_import(mc, x); - mp_copy_into(r, imported); - mp_free(imported); -} - -/* - * Exporting a number means multiplying it by r^{-1}, which is exactly - * what monty_reduce does anyway, so we just do that. - */ -void monty_export_into(MontyContext *mc, mp_int *r, mp_int *x) -{ - assert(x->nw <= 2*mc->rw); - mp_int reduced = monty_reduce_internal(mc, x, *mc->scratch); - mp_copy_into(r, &reduced); - mp_clear(mc->scratch); -} - -mp_int *monty_export(MontyContext *mc, mp_int *x) -{ - mp_int *toret = mp_make_sized(mc->rw); - monty_export_into(mc, toret, x); - return toret; -} - -static void monty_reduce(MontyContext *mc, mp_int *x) -{ - mp_int reduced = monty_reduce_internal(mc, x, *mc->scratch); - mp_copy_into(x, &reduced); - mp_clear(mc->scratch); -} - -mp_int *monty_pow(MontyContext *mc, mp_int *base, mp_int *exponent) -{ - /* square builds up powers of the form base^{2^i}. */ - mp_int *square = mp_copy(base); - size_t i = 0; - - /* out accumulates the output value. Starts at 1 (in Montgomery - * representation) and we multiply in each base^{2^i}. */ - mp_int *out = mp_copy(mc->powers_of_r_mod_m[0]); - - /* tmp holds each product we compute and reduce. */ - mp_int *tmp = mp_make_sized(mc->rw * 2); - - while (true) { - mp_mul_into(tmp, out, square); - monty_reduce(mc, tmp); - mp_select_into(out, out, tmp, mp_get_bit(exponent, i)); - - if (++i >= exponent->nw * BIGNUM_INT_BITS) - break; - - mp_mul_into(tmp, square, square); - monty_reduce(mc, tmp); - mp_copy_into(square, tmp); - } - - mp_free(square); - mp_free(tmp); - mp_clear(mc->scratch); - return out; -} - -mp_int *mp_modpow(mp_int *base, mp_int *exponent, mp_int *modulus) -{ - assert(modulus->nw > 0); - assert(modulus->w[0] & 1); - - MontyContext *mc = monty_new(modulus); - mp_int *m_base = monty_import(mc, base); - mp_int *m_out = monty_pow(mc, m_base, exponent); - mp_int *out = monty_export(mc, m_out); - mp_free(m_base); - mp_free(m_out); - monty_free(mc); - return out; -} - -/* - * Given two coprime nonzero input integers a,b, returns two integers - * A,B such that A*a - B*b = 1. A,B will be the minimal non-negative - * pair satisfying that criterion, which is equivalent to saying that - * 0<=Ab, and gcd(a,b) = - * gcd(b,(a-b)/2). - * - * For this application, I always expect the actual gcd to be coprime, - * so we can rule out the 'both even' initial case. So this function - * just performs a sequence of reductions in the following form: - * - * - if a,b are both odd, sort them so that a > b, and replace a with - * b-a; otherwise sort them so that a is the even one - * - either way, now a is even and b is odd, so divide a by 2. - * - * The big change to Stein's algorithm is that we need the Bezout - * coefficients as output, not just the gcd. So we need to know how to - * generate those in each case, based on the coefficients from the - * reduced pair of numbers: - * - * - If a is even, and u,v are such that u*(a/2) + v*b = 1: - * + if u is also even, then this is just (u/2)*a + v*b = 1 - * + otherwise, (u+b)*(a/2) + (v-a/2)*b is also equal to 1, and - * since u and b are both odd, (u+b)/2 is an integer, so we have - * ((u+b)/2)*a + (v-a/2)*b = 1. - * - * - If a,b are both odd, and u,v are such that u*b + v*(a-b) = 1, - * then v*a + (u-v)*b = 1. - * - * In the case where we passed from (a,b) to (b,(a-b)/2), we regard it - * as having first subtracted b from a and then halved a, so both of - * these transformations must be done in sequence. - * - * The code below transforms this from a recursive to an iterative - * algorithm. We first reduce a,b to 0,1, recording at each stage - * whether we did the initial subtraction, and whether we had to swap - * the two values; then we iterate backwards over that record of what - * we did, applying the above rules for building up the Bezout - * coefficients as we go. Of course, all the case analysis is done by - * the usual bit-twiddling conditionalisation to avoid data-dependent - * control flow. - * - * Also, since these mp_ints are generally treated as unsigned, we - * store the coefficients by absolute value, with the semantics that - * they always have opposite sign, and in the unwinding loop we keep a - * bit indicating whether Aa-Bb is currently expected to be +1 or -1, - * so that we can do one final conditional adjustment if it's -1. - * - * Once the reduction rules have managed to reduce the input numbers - * to (0,1), then they are stable (the next reduction will always - * divide the even one by 2, which maps 0 to 0). So it doesn't matter - * if we do more steps of the algorithm than necessary; hence, for - * constant time, we just need to find the maximum number we could - * _possibly_ require, and do that many. - * - * If a,b < 2^n, at most 2n iterations are required. Proof: consider - * the quantity Q = log_2(a) + log_2(b). Every step halves one of the - * numbers (and may also reduce one of them further by doing a - * subtraction beforehand, but in the worst case, not by much or not - * at all). So Q reduces by at least 1 per iteration, and it starts - * off with a value at most 2n. - * - * The worst case inputs (I think) are where x=2^{n-1} and y=2^n-1 - * (i.e. x is a power of 2 and y is all 1s). In that situation, the - * first n-1 steps repeatedly halve x until it's 1, and then there are - * n further steps each of which subtracts 1 from y and halves it. - */ -static void mp_bezout_into(mp_int *a_coeff_out, mp_int *b_coeff_out, - mp_int *a_in, mp_int *b_in) -{ - size_t nw = size_t_max(1, size_t_max(a_in->nw, b_in->nw)); - - /* Make mutable copies of the input numbers */ - mp_int *a = mp_make_sized(nw), *b = mp_make_sized(nw); - mp_copy_into(a, a_in); - mp_copy_into(b, b_in); - - /* Space to build up the output coefficients, with an extra word - * so that intermediate values can overflow off the top and still - * right-shift back down to the correct value */ - mp_int *ac = mp_make_sized(nw + 1), *bc = mp_make_sized(nw + 1); - - /* And a general-purpose temp register */ - mp_int *tmp = mp_make_sized(nw); - - /* Space to record the sequence of reduction steps to unwind. We - * make it a BignumInt for no particular reason except that (a) - * mp_make_sized conveniently zeroes the allocation and mp_free - * wipes it, and (b) this way I can use mp_dump() if I have to - * debug this code. */ - size_t steps = 2 * nw * BIGNUM_INT_BITS; - mp_int *record = mp_make_sized( - (steps*2 + BIGNUM_INT_BITS - 1) / BIGNUM_INT_BITS); - - for (size_t step = 0; step < steps; step++) { - /* - * If a and b are both odd, we want to sort them so that a is - * larger. But if one is even, we want to sort them so that a - * is the even one. - */ - unsigned swap_if_both_odd = mp_cmp_hs(b, a); - unsigned swap_if_one_even = a->w[0] & 1; - unsigned both_odd = a->w[0] & b->w[0] & 1; - unsigned swap = swap_if_one_even ^ ( - (swap_if_both_odd ^ swap_if_one_even) & both_odd); - - mp_cond_swap(a, b, swap); - - /* - * If a,b are both odd, then a is the larger number, so - * subtract the smaller one from it. - */ - mp_cond_sub_into(a, a, b, both_odd); - - /* - * Now a is even, so divide it by two. - */ - mp_rshift_fixed_into(a, a, 1); - - /* - * Record the two 1-bit values both_odd and swap. - */ - mp_set_bit(record, step*2, both_odd); - mp_set_bit(record, step*2+1, swap); - } - - /* - * Now we expect to have reduced the two numbers to 0 and 1, - * although we don't know which way round. (But we avoid checking - * this by assertion; sometimes we'll need to do this computation - * without giving away that we already know the inputs were bogus. - * So we'd prefer to just press on and return nonsense.) - */ - - /* - * So their Bezout coefficients at this point are simply - * themselves. - */ - mp_copy_into(ac, a); - mp_copy_into(bc, b); - - /* - * We'll maintain the invariant as we unwind that ac * a - bc * b - * is either +1 or -1, and we'll remember which. (We _could_ keep - * it at +1 the whole time, but it would cost more work every time - * round the loop, so it's cheaper to fix that up once at the - * end.) - * - * Initially, the result is +1 if a was the nonzero value after - * reduction, and -1 if b was. - */ - unsigned minus_one = b->w[0]; - - for (size_t step = steps; step-- > 0 ;) { - /* - * Recover the data from the step we're unwinding. - */ - unsigned both_odd = mp_get_bit(record, step*2); - unsigned swap = mp_get_bit(record, step*2+1); - - /* - * Unwind the division: if our coefficient of a is odd, we - * adjust the coefficients by +b and +a respectively. - */ - unsigned adjust = ac->w[0] & 1; - mp_cond_add_into(ac, ac, b, adjust); - mp_cond_add_into(bc, bc, a, adjust); - - /* - * Now ac is definitely even, so we divide it by two. - */ - mp_rshift_fixed_into(ac, ac, 1); - - /* - * Now unwind the subtraction, if there was one, by adding - * ac to bc. - */ - mp_cond_add_into(bc, bc, ac, both_odd); - - /* - * Undo the transformation of the input numbers, by - * multiplying a by 2 and then adding b to a (the latter - * only if both_odd). - */ - mp_lshift_fixed_into(a, a, 1); - mp_cond_add_into(a, a, b, both_odd); - - /* - * Finally, undo the swap. If we do swap, this also - * reverses the sign of the current result ac*a+bc*b. - */ - mp_cond_swap(a, b, swap); - mp_cond_swap(ac, bc, swap); - minus_one ^= swap; - } - - /* - * Now we expect to have recovered the input a,b. - */ - assert(mp_cmp_eq(a, a_in) & mp_cmp_eq(b, b_in)); - - /* - * But we might find that our current result is -1 instead of +1, - * that is, we have A',B' such that A'a - B'b = -1. - * - * In that situation, we set A = b-A' and B = a-B', giving us - * Aa-Bb = ab - A'a - ab + B'b = +1. - */ - mp_sub_into(tmp, b, ac); - mp_select_into(ac, ac, tmp, minus_one); - mp_sub_into(tmp, a, bc); - mp_select_into(bc, bc, tmp, minus_one); - - /* - * Now we really are done. Return the outputs. - */ - if (a_coeff_out) - mp_copy_into(a_coeff_out, ac); - if (b_coeff_out) - mp_copy_into(b_coeff_out, bc); - - mp_free(a); - mp_free(b); - mp_free(ac); - mp_free(bc); - mp_free(tmp); - mp_free(record); -} - -mp_int *mp_invert(mp_int *x, mp_int *m) -{ - mp_int *result = mp_make_sized(m->nw); - mp_bezout_into(result, NULL, x, m); - return result; -} - -static uint32_t recip_approx_32(uint32_t x) -{ - /* - * Given an input x in [2^31,2^32), i.e. a uint32_t with its high - * bit set, this function returns an approximation to 2^63/x, - * computed using only multiplications and bit shifts just in case - * the C divide operator has non-constant time (either because the - * underlying machine instruction does, or because the operator - * expands to a library function on a CPU without hardware - * division). - * - * The coefficients are derived from those of the degree-9 - * polynomial which is the minimax-optimal approximation to that - * function on the given interval (generated using the Remez - * algorithm), converted into integer arithmetic with shifts used - * to maximise the number of significant bits at every state. (A - * sort of 'static floating point' - the exponent is statically - * known at every point in the code, so it never needs to be - * stored at run time or to influence runtime decisions.) - * - * Exhaustive iteration over the whole input space shows the - * largest possible error to be 1686.54. (The input value - * attaining that bound is 4226800006 == 0xfbefd986, whose true - * reciprocal is 2182116973.540... == 0x8210766d.8a6..., whereas - * this function returns 2182115287 == 0x82106fd7.) - */ - uint64_t r = 0x92db03d6ULL; - r = 0xf63e71eaULL - ((r*x) >> 34); - r = 0xb63721e8ULL - ((r*x) >> 34); - r = 0x9c2da00eULL - ((r*x) >> 33); - r = 0xaada0bb8ULL - ((r*x) >> 32); - r = 0xf75cd403ULL - ((r*x) >> 31); - r = 0xecf97a41ULL - ((r*x) >> 31); - r = 0x90d876cdULL - ((r*x) >> 31); - r = 0x6682799a0ULL - ((r*x) >> 26); - return r; -} - -void mp_divmod_into(mp_int *n, mp_int *d, mp_int *q_out, mp_int *r_out) -{ - assert(!mp_eq_integer(d, 0)); - - /* - * We do division by using Newton-Raphson iteration to converge to - * the reciprocal of d (or rather, R/d for R a sufficiently large - * power of 2); then we multiply that reciprocal by n; and we - * finish up with conditional subtraction. - * - * But we have to do it in a fixed number of N-R iterations, so we - * need some error analysis to know how many we might need. - * - * The iteration is derived by defining f(r) = d - R/r. - * Differentiating gives f'(r) = R/r^2, and the Newton-Raphson - * formula applied to those functions gives - * - * r_{i+1} = r_i - f(r_i) / f'(r_i) - * = r_i - (d - R/r_i) r_i^2 / R - * = r_i (2 R - d r_i) / R - * - * Now let e_i be the error in a given iteration, in the sense - * that - * - * d r_i = R + e_i - * i.e. e_i/R = (r_i - r_true) / r_true - * - * so e_i is the _relative_ error in r_i. - * - * We must also introduce a rounding-error term, because the - * division by R always gives an integer. This might make the - * output off by up to 1 (in the negative direction, because - * right-shifting gives floor of the true quotient). So when we - * divide by R, we must imagine adding some f in [0,1). Then we - * have - * - * d r_{i+1} = d r_i (2 R - d r_i) / R - d f - * = (R + e_i) (R - e_i) / R - d f - * = (R^2 - e_i^2) / R - d f - * = R - (e_i^2 / R + d f) - * => e_{i+1} = - (e_i^2 / R + d f) - * - * The sum of two positive quantities is bounded above by twice - * their max, and max |f| = 1, so we can bound this as follows: - * - * |e_{i+1}| <= 2 max (e_i^2/R, d) - * |e_{i+1}/R| <= 2 max ((e_i/R)^2, d/R) - * log2 |R/e_{i+1}| <= min (2 log2 |R/e_i|, log2 |R/d|) - 1 - * - * which tells us that the number of 'good' bits - i.e. - * log2(R/e_i) - very nearly doubles at every iteration (apart - * from that subtraction of 1), until it gets to the same size as - * log2(R/d). In other words, the size of R in bits has to be the - * size of denominator we're putting in, _plus_ the amount of - * precision we want to get back out. - * - * So when we multiply n (the input numerator) by our final - * reciprocal approximation r, but actually r differs from R/d by - * up to 2, then it follows that - * - * n/d - nr/R = n/d - [ n (R/d + e) ] / R - * = n/d - [ (n/d) R + n e ] / R - * = -ne/R - * => 0 <= n/d - nr/R < 2n/R - * - * so our computed quotient can differ from the true n/d by up to - * 2n/R. Hence, as long as we also choose R large enough that 2n/R - * is bounded above by a constant, we can guarantee a bounded - * number of final conditional-subtraction steps. - */ - - /* - * Get at least 32 of the most significant bits of the input - * number. - */ - size_t hiword_index = 0; - uint64_t hibits = 0, lobits = 0; - mp_find_highest_nonzero_word_pair(d, 64 - BIGNUM_INT_BITS, - &hiword_index, &hibits, &lobits); - - /* - * Make a shifted combination of those two words which puts the - * topmost bit of the number at bit 63. - */ - size_t shift_up = 0; - for (size_t i = BIGNUM_INT_BITS_BITS; i-- > 0;) { - size_t sl = 1 << i; /* left shift count */ - size_t sr = 64 - sl; /* complementary right-shift count */ - - /* Should we shift up? */ - unsigned indicator = 1 ^ normalise_to_1_u64(hibits >> sr); - - /* If we do, what will we get? */ - uint64_t new_hibits = (hibits << sl) | (lobits >> sr); - uint64_t new_lobits = lobits << sl; - size_t new_shift_up = shift_up + sl; - - /* Conditionally swap those values in. */ - hibits ^= (hibits ^ new_hibits ) & -(uint64_t)indicator; - lobits ^= (lobits ^ new_lobits ) & -(uint64_t)indicator; - shift_up ^= (shift_up ^ new_shift_up ) & -(size_t) indicator; - } - - /* - * So now we know the most significant 32 bits of d are at the top - * of hibits. Approximate the reciprocal of those bits. - */ - lobits = (uint64_t)recip_approx_32(hibits >> 32) << 32; - hibits = 0; - - /* - * And shift that up by as many bits as the input was shifted up - * just now, so that the product of this approximation and the - * actual input will be close to a fixed power of two regardless - * of where the MSB was. - * - * I do this in another log n individual passes, partly in case - * the CPU's register-controlled shift operation isn't - * time-constant, and also in case the compiler code-generates - * uint64_t shifts out of a variable number of smaller-word shift - * instructions, e.g. by splitting up into cases. - */ - for (size_t i = BIGNUM_INT_BITS_BITS; i-- > 0;) { - size_t sl = 1 << i; /* left shift count */ - size_t sr = 64 - sl; /* complementary right-shift count */ - - /* Should we shift up? */ - unsigned indicator = 1 & (shift_up >> i); - - /* If we do, what will we get? */ - uint64_t new_hibits = (hibits << sl) | (lobits >> sr); - uint64_t new_lobits = lobits << sl; - - /* Conditionally swap those values in. */ - hibits ^= (hibits ^ new_hibits ) & -(uint64_t)indicator; - lobits ^= (lobits ^ new_lobits ) & -(uint64_t)indicator; - } - - /* - * The product of the 128-bit value now in hibits:lobits with the - * 128-bit value we originally retrieved in the same variables - * will be in the vicinity of 2^191. So we'll take log2(R) to be - * 191, plus a multiple of BIGNUM_INT_BITS large enough to allow R - * to hold the combined sizes of n and d. - */ - size_t log2_R; - { - size_t max_log2_n = (n->nw + d->nw) * BIGNUM_INT_BITS; - log2_R = max_log2_n + 3; - log2_R -= size_t_min(191, log2_R); - log2_R = (log2_R + BIGNUM_INT_BITS - 1) & ~(BIGNUM_INT_BITS - 1); - log2_R += 191; - } - - /* Number of words in a bignum capable of holding numbers the size - * of twice R. */ - size_t rw = ((log2_R+2) + BIGNUM_INT_BITS - 1) / BIGNUM_INT_BITS; - - /* - * Now construct our full-sized starting reciprocal approximation. - */ - mp_int *r_approx = mp_make_sized(rw); - size_t output_bit_index; - { - /* Where in the input number did the input 128-bit value come from? */ - size_t input_bit_index = - (hiword_index * BIGNUM_INT_BITS) - (128 - BIGNUM_INT_BITS); - - /* So how far do we need to shift our 64-bit output, if the - * product of those two fixed-size values is 2^191 and we want - * to make it 2^log2_R instead? */ - output_bit_index = log2_R - 191 - input_bit_index; - - /* If we've done all that right, it should be a whole number - * of words. */ - assert(output_bit_index % BIGNUM_INT_BITS == 0); - size_t output_word_index = output_bit_index / BIGNUM_INT_BITS; - - mp_add_integer_into_shifted_by_words( - r_approx, r_approx, lobits, output_word_index); - mp_add_integer_into_shifted_by_words( - r_approx, r_approx, hibits, - output_word_index + 64 / BIGNUM_INT_BITS); - } - - /* - * Make the constant 2*R, which we'll need in the iteration. - */ - mp_int *two_R = mp_make_sized(rw); - mp_add_integer_into_shifted_by_words( - two_R, two_R, (BignumInt)1 << ((log2_R+1) % BIGNUM_INT_BITS), - (log2_R+1) / BIGNUM_INT_BITS); - - /* - * Scratch space. - */ - mp_int *dr = mp_make_sized(rw + d->nw); - mp_int *diff = mp_make_sized(size_t_max(rw, dr->nw)); - mp_int *product = mp_make_sized(rw + diff->nw); - size_t scratchsize = size_t_max( - mp_mul_scratchspace(dr->nw, r_approx->nw, d->nw), - mp_mul_scratchspace(product->nw, r_approx->nw, diff->nw)); - mp_int *scratch = mp_make_sized(scratchsize); - mp_int product_shifted = mp_make_alias( - product, log2_R / BIGNUM_INT_BITS, product->nw); - - /* - * Initial error estimate: the 32-bit output of recip_approx_32 - * differs by less than 2048 (== 2^11) from the true top 32 bits - * of the reciprocal, so the relative error is at most 2^11 - * divided by the 32-bit reciprocal, which at worst is 2^11/2^31 = - * 2^-20. So even in the worst case, we have 20 good bits of - * reciprocal to start with. - */ - size_t good_bits = 31 - 11; - size_t good_bits_needed = BIGNUM_INT_BITS * n->nw + 4; /* add a few */ - - /* - * Now do Newton-Raphson iterations until we have reason to think - * they're not converging any more. - */ - while (good_bits < good_bits_needed) { - /* - * Compute the next iterate. - */ - mp_mul_internal(dr, r_approx, d, *scratch); - mp_sub_into(diff, two_R, dr); - mp_mul_internal(product, r_approx, diff, *scratch); - mp_rshift_fixed_into(r_approx, &product_shifted, - log2_R % BIGNUM_INT_BITS); - - /* - * Adjust the error estimate. - */ - good_bits = good_bits * 2 - 1; - } - - mp_free(dr); - mp_free(diff); - mp_free(product); - mp_free(scratch); - - /* - * Now we've got our reciprocal, we can compute the quotient, by - * multiplying in n and then shifting down by log2_R bits. - */ - mp_int *quotient_full = mp_mul(r_approx, n); - mp_int quotient_alias = mp_make_alias( - quotient_full, log2_R / BIGNUM_INT_BITS, quotient_full->nw); - mp_int *quotient = mp_make_sized(n->nw); - mp_rshift_fixed_into(quotient, "ient_alias, log2_R % BIGNUM_INT_BITS); - - /* - * Next, compute the remainder. - */ - mp_int *remainder = mp_make_sized(d->nw); - mp_mul_into(remainder, quotient, d); - mp_sub_into(remainder, n, remainder); - - /* - * Finally, two conditional subtractions to fix up any remaining - * rounding error. (I _think_ one should be enough, but this - * routine isn't time-critical enough to take chances.) - */ - unsigned q_correction = 0; - for (unsigned iter = 0; iter < 2; iter++) { - unsigned need_correction = mp_cmp_hs(remainder, d); - mp_cond_sub_into(remainder, remainder, d, need_correction); - q_correction += need_correction; - } - mp_add_integer_into(quotient, quotient, q_correction); - - /* - * Now we should have a perfect answer, i.e. 0 <= r < d. - */ - assert(!mp_cmp_hs(remainder, d)); - - if (q_out) - mp_copy_into(q_out, quotient); - if (r_out) - mp_copy_into(r_out, remainder); - - mp_free(r_approx); - mp_free(two_R); - mp_free(quotient_full); - mp_free(quotient); - mp_free(remainder); -} - -mp_int *mp_div(mp_int *n, mp_int *d) -{ - mp_int *q = mp_make_sized(n->nw); - mp_divmod_into(n, d, q, NULL); - return q; -} - -mp_int *mp_mod(mp_int *n, mp_int *d) -{ - mp_int *r = mp_make_sized(d->nw); - mp_divmod_into(n, d, NULL, r); - return r; -} - -mp_int *mp_modmul(mp_int *x, mp_int *y, mp_int *modulus) -{ - mp_int *product = mp_mul(x, y); - mp_int *reduced = mp_mod(product, modulus); - mp_free(product); - return reduced; -} - -mp_int *mp_modadd(mp_int *x, mp_int *y, mp_int *modulus) -{ - mp_int *sum = mp_add(x, y); - mp_int *reduced = mp_mod(sum, modulus); - mp_free(sum); - return reduced; -} - -mp_int *mp_modsub(mp_int *x, mp_int *y, mp_int *modulus) -{ - mp_int *diff = mp_make_sized(size_t_max(x->nw, y->nw)); - mp_sub_into(diff, x, y); - unsigned negate = mp_cmp_hs(y, x); - mp_cond_negate(diff, diff, negate); - mp_int *residue = mp_mod(diff, modulus); - mp_cond_negate(residue, residue, negate); - /* If we've just negated the residue, then it will be < 0 and need - * the modulus adding to it to make it positive - *except* if the - * residue was zero when we negated it. */ - unsigned make_positive = negate & ~mp_eq_integer(residue, 0); - mp_cond_add_into(residue, residue, modulus, make_positive); - mp_free(diff); - return residue; -} - -static mp_int *mp_modadd_in_range(mp_int *x, mp_int *y, mp_int *modulus) -{ - mp_int *sum = mp_make_sized(modulus->nw); - unsigned carry = mp_add_into_internal(sum, x, y); - mp_cond_sub_into(sum, sum, modulus, carry | mp_cmp_hs(sum, modulus)); - return sum; -} - -static mp_int *mp_modsub_in_range(mp_int *x, mp_int *y, mp_int *modulus) -{ - mp_int *diff = mp_make_sized(modulus->nw); - mp_sub_into(diff, x, y); - mp_cond_add_into(diff, diff, modulus, 1 ^ mp_cmp_hs(x, y)); - return diff; -} - -mp_int *monty_add(MontyContext *mc, mp_int *x, mp_int *y) -{ - return mp_modadd_in_range(x, y, mc->m); -} - -mp_int *monty_sub(MontyContext *mc, mp_int *x, mp_int *y) -{ - return mp_modsub_in_range(x, y, mc->m); -} - -void mp_min_into(mp_int *r, mp_int *x, mp_int *y) -{ - mp_select_into(r, x, y, mp_cmp_hs(x, y)); -} - -void mp_max_into(mp_int *r, mp_int *x, mp_int *y) -{ - mp_select_into(r, y, x, mp_cmp_hs(x, y)); -} - -mp_int *mp_min(mp_int *x, mp_int *y) -{ - mp_int *r = mp_make_sized(size_t_min(x->nw, y->nw)); - mp_min_into(r, x, y); - return r; -} - -mp_int *mp_max(mp_int *x, mp_int *y) -{ - mp_int *r = mp_make_sized(size_t_max(x->nw, y->nw)); - mp_max_into(r, x, y); - return r; -} - -mp_int *mp_power_2(size_t power) -{ - mp_int *x = mp_new(power + 1); - mp_set_bit(x, power, 1); - return x; -} - -struct ModsqrtContext { - mp_int *p; /* the prime */ - MontyContext *mc; /* for doing arithmetic mod p */ - - /* Decompose p-1 as 2^e k, for positive integer e and odd k */ - size_t e; - mp_int *k; - mp_int *km1o2; /* (k-1)/2 */ - - /* The user-provided value z which is not a quadratic residue mod - * p, and its kth power. Both in Montgomery form. */ - mp_int *z, *zk; -}; - -ModsqrtContext *modsqrt_new(mp_int *p, mp_int *any_nonsquare_mod_p) -{ - ModsqrtContext *sc = snew(ModsqrtContext); - memset(sc, 0, sizeof(ModsqrtContext)); - - sc->p = mp_copy(p); - sc->mc = monty_new(sc->p); - sc->z = monty_import(sc->mc, any_nonsquare_mod_p); - - /* Find the lowest set bit in p-1. Since this routine expects p to - * be non-secret (typically a well-known standard elliptic curve - * parameter), for once we don't need clever bit tricks. */ - for (sc->e = 1; sc->e < BIGNUM_INT_BITS * p->nw; sc->e++) - if (mp_get_bit(p, sc->e)) - break; - - sc->k = mp_rshift_fixed(p, sc->e); - sc->km1o2 = mp_rshift_fixed(sc->k, 1); - - /* Leave zk to be filled in lazily, since it's more expensive to - * compute. If this context turns out never to be needed, we can - * save the bulk of the setup time this way. */ - - return sc; -} - -static void modsqrt_lazy_setup(ModsqrtContext *sc) -{ - if (!sc->zk) - sc->zk = monty_pow(sc->mc, sc->z, sc->k); -} - -void modsqrt_free(ModsqrtContext *sc) -{ - monty_free(sc->mc); - mp_free(sc->p); - mp_free(sc->z); - mp_free(sc->k); - mp_free(sc->km1o2); - - if (sc->zk) - mp_free(sc->zk); - - sfree(sc); -} - -mp_int *mp_modsqrt(ModsqrtContext *sc, mp_int *x, unsigned *success) -{ - mp_int *mx = monty_import(sc->mc, x); - mp_int *mroot = monty_modsqrt(sc, mx, success); - mp_free(mx); - mp_int *root = monty_export(sc->mc, mroot); - mp_free(mroot); - return root; -} - -/* - * Modular square root, using an algorithm more or less similar to - * Tonelli-Shanks but adapted for constant time. - * - * The basic idea is to write p-1 = k 2^e, where k is odd and e > 0. - * Then the multiplicative group mod p (call it G) has a sequence of - * e+1 nested subgroups G = G_0 > G_1 > G_2 > ... > G_e, where each - * G_i is exactly half the size of G_{i-1} and consists of all the - * squares of elements in G_{i-1}. So the innermost group G_e has - * order k, which is odd, and hence within that group you can take a - * square root by raising to the power (k+1)/2. - * - * Our strategy is to iterate over these groups one by one and make - * sure the number x we're trying to take the square root of is inside - * each one, by adjusting it if it isn't. - * - * Suppose g is a primitive root of p, i.e. a generator of G_0. (We - * don't actually need to know what g _is_; we just imagine it for the - * sake of understanding.) Then G_i consists of precisely the (2^i)th - * powers of g, and hence, you can tell if a number is in G_i if - * raising it to the power k 2^{e-i} gives 1. So the conceptual - * algorithm goes: for each i, test whether x is in G_i by that - * method. If it isn't, then the previous iteration ensured it's in - * G_{i-1}, so it will be an odd power of g^{2^{i-1}}, and hence - * multiplying by any other odd power of g^{2^{i-1}} will give x' in - * G_i. And we have one of those, because our non-square z is an odd - * power of g, so z^{2^{i-1}} is an odd power of g^{2^{i-1}}. - * - * (There's a special case in the very first iteration, where we don't - * have a G_{i-1}. If it turns out that x is not even in G_1, that - * means it's not a square, so we set *success to 0. We still run the - * rest of the algorithm anyway, for the sake of constant time, but we - * don't give a hoot what it returns.) - * - * When we get to the end and have x in G_e, then we can take its - * square root by raising to (k+1)/2. But of course that's not the - * square root of the original input - it's only the square root of - * the adjusted version we produced during the algorithm. To get the - * true output answer we also have to multiply by a power of z, - * namely, z to the power of _half_ whatever we've been multiplying in - * as we go along. (The power of z we multiplied in must have been - * even, because the case in which we would have multiplied in an odd - * power of z is the i=0 case, in which we instead set the failure - * flag.) - * - * The code below is an optimised version of that basic idea, in which - * we _start_ by computing x^k so as to be able to test membership in - * G_i by only a few squarings rather than a full from-scratch modpow - * every time; we also start by computing our candidate output value - * x^{(k+1)/2}. So when the above description says 'adjust x by z^i' - * for some i, we have to adjust our running values of x^k and - * x^{(k+1)/2} by z^{ik} and z^{ik/2} respectively (the latter is safe - * because, as above, i is always even). And it turns out that we - * don't actually have to store the adjusted version of x itself at - * all - we _only_ keep those two powers of it. - */ -mp_int *monty_modsqrt(ModsqrtContext *sc, mp_int *x, unsigned *success) -{ - modsqrt_lazy_setup(sc); - - mp_int *scratch_to_free = mp_make_sized(3 * sc->mc->rw); - mp_int scratch = *scratch_to_free; - - /* - * Compute toret = x^{(k+1)/2}, our starting point for the output - * square root, and also xk = x^k which we'll use as we go along - * for knowing when to apply correction factors. We do this by - * first computing x^{(k-1)/2}, then multiplying it by x, then - * multiplying the two together. - */ - mp_int *toret = monty_pow(sc->mc, x, sc->km1o2); - mp_int xk = mp_alloc_from_scratch(&scratch, sc->mc->rw); - mp_copy_into(&xk, toret); - monty_mul_into(sc->mc, toret, toret, x); - monty_mul_into(sc->mc, &xk, toret, &xk); - - mp_int tmp = mp_alloc_from_scratch(&scratch, sc->mc->rw); - - mp_int power_of_zk = mp_alloc_from_scratch(&scratch, sc->mc->rw); - mp_copy_into(&power_of_zk, sc->zk); - - for (size_t i = 0; i < sc->e; i++) { - mp_copy_into(&tmp, &xk); - for (size_t j = i+1; j < sc->e; j++) - monty_mul_into(sc->mc, &tmp, &tmp, &tmp); - unsigned eq1 = mp_cmp_eq(&tmp, monty_identity(sc->mc)); - - if (i == 0) { - /* One special case: if x=0, then no power of x will ever - * equal 1, but we should still report success on the - * grounds that 0 does have a square root mod p. */ - *success = eq1 | mp_eq_integer(x, 0); - } else { - monty_mul_into(sc->mc, &tmp, toret, &power_of_zk); - mp_select_into(toret, &tmp, toret, eq1); - - monty_mul_into(sc->mc, &power_of_zk, - &power_of_zk, &power_of_zk); - - monty_mul_into(sc->mc, &tmp, &xk, &power_of_zk); - mp_select_into(&xk, &tmp, &xk, eq1); - } - } - - mp_free(scratch_to_free); - - return toret; -} - -mp_int *mp_random_bits_fn(size_t bits, random_read_fn_t random_read) -{ - size_t bytes = (bits + 7) / 8; - uint8_t *randbuf = snewn(bytes, uint8_t); - random_read(randbuf, bytes); - if (bytes) - randbuf[0] &= (2 << ((bits-1) & 7)) - 1; - mp_int *toret = mp_from_bytes_be(make_ptrlen(randbuf, bytes)); - smemclr(randbuf, bytes); - sfree(randbuf); - return toret; -} - -mp_int *mp_random_in_range_fn(mp_int *lo, mp_int *hi, random_read_fn_t rf) -{ - mp_int *n_outcomes = mp_sub(hi, lo); - - /* - * It would be nice to generate our random numbers in such a way - * as to make every possible outcome literally equiprobable. But - * we can't do that in constant time, so we have to go for a very - * close approximation instead. I'm going to take the view that a - * factor of (1+2^-128) between the probabilities of two outcomes - * is acceptable on the grounds that you'd have to examine so many - * outputs to even detect it. - */ - mp_int *unreduced = mp_random_bits_fn(mp_max_bits(n_outcomes) + 128, rf); - mp_int *reduced = mp_mod(unreduced, n_outcomes); - mp_add_into(reduced, reduced, lo); - mp_free(unreduced); - mp_free(n_outcomes); - return reduced; -} +#include +#include +#include + +#include "defs.h" +#include "misc.h" +#include "puttymem.h" + +#include "mpint.h" +#include "mpint_i.h" + +#define SIZE_T_BITS (CHAR_BIT * sizeof(size_t)) + +/* + * Inline helpers to take min and max of size_t values, used + * throughout this code. + */ +static inline size_t size_t_min(size_t a, size_t b) +{ + return a < b ? a : b; +} +static inline size_t size_t_max(size_t a, size_t b) +{ + return a > b ? a : b; +} + +/* + * Helper to fetch a word of data from x with array overflow checking. + * If x is too short to have that word, 0 is returned. + */ +static inline BignumInt mp_word(mp_int *x, size_t i) +{ + return i < x->nw ? x->w[i] : 0; +} + +static mp_int *mp_make_sized(size_t nw) +{ + mp_int *x = snew_plus(mp_int, nw * sizeof(BignumInt)); + assert(nw); /* we outlaw the zero-word mp_int */ + x->nw = nw; + x->w = snew_plus_get_aux(x); + mp_clear(x); + return x; +} + +mp_int *mp_new(size_t maxbits) +{ + size_t words = (maxbits + BIGNUM_INT_BITS - 1) / BIGNUM_INT_BITS; + return mp_make_sized(words); +} + +mp_int *mp_from_integer(uintmax_t n) +{ + mp_int *x = mp_make_sized( + (sizeof(n) + BIGNUM_INT_BYTES - 1) / BIGNUM_INT_BYTES); + for (size_t i = 0; i < x->nw; i++) + x->w[i] = n >> (i * BIGNUM_INT_BITS); + return x; +} + +size_t mp_max_bytes(mp_int *x) +{ + return x->nw * BIGNUM_INT_BYTES; +} + +size_t mp_max_bits(mp_int *x) +{ + return x->nw * BIGNUM_INT_BITS; +} + +void mp_free(mp_int *x) +{ + mp_clear(x); + smemclr(x, sizeof(*x)); + sfree(x); +} + +void mp_dump(FILE *fp, const char *prefix, mp_int *x, const char *suffix) +{ + fprintf(fp, "%s0x", prefix); + for (size_t i = mp_max_bytes(x); i-- > 0 ;) + fprintf(fp, "%02X", mp_get_byte(x, i)); + fputs(suffix, fp); +} + +void mp_copy_into(mp_int *dest, mp_int *src) +{ + size_t copy_nw = size_t_min(dest->nw, src->nw); + memmove(dest->w, src->w, copy_nw * sizeof(BignumInt)); + smemclr(dest->w + copy_nw, (dest->nw - copy_nw) * sizeof(BignumInt)); +} + +/* + * Conditional selection is done by negating 'which', to give a mask + * word which is all 1s if which==1 and all 0s if which==0. Then you + * can select between two inputs a,b without data-dependent control + * flow by XORing them to get their difference; ANDing with the mask + * word to replace that difference with 0 if which==0; and XORing that + * into a, which will either turn it into b or leave it alone. + * + * This trick will be used throughout this code and taken as read the + * rest of the time (or else I'd be here all week typing comments), + * but I felt I ought to explain it in words _once_. + */ +void mp_select_into(mp_int *dest, mp_int *src0, mp_int *src1, + unsigned which) +{ + BignumInt mask = -(BignumInt)(1 & which); + for (size_t i = 0; i < dest->nw; i++) { + BignumInt srcword0 = mp_word(src0, i), srcword1 = mp_word(src1, i); + dest->w[i] = srcword0 ^ ((srcword1 ^ srcword0) & mask); + } +} + +void mp_cond_swap(mp_int *x0, mp_int *x1, unsigned swap) +{ + assert(x0->nw == x1->nw); + volatile BignumInt mask = -(BignumInt)(1 & swap); + for (size_t i = 0; i < x0->nw; i++) { + BignumInt diff = (x0->w[i] ^ x1->w[i]) & mask; + x0->w[i] ^= diff; + x1->w[i] ^= diff; + } +} + +void mp_clear(mp_int *x) +{ + smemclr(x->w, x->nw * sizeof(BignumInt)); +} + +void mp_cond_clear(mp_int *x, unsigned clear) +{ + BignumInt mask = ~-(BignumInt)(1 & clear); + for (size_t i = 0; i < x->nw; i++) + x->w[i] &= mask; +} + +/* + * Common code between mp_from_bytes_{le,be} which reads bytes in an + * arbitrary arithmetic progression. + */ +static mp_int *mp_from_bytes_int(ptrlen bytes, size_t m, size_t c) +{ + size_t nw = (bytes.len + BIGNUM_INT_BYTES - 1) / BIGNUM_INT_BYTES; + nw = size_t_max(nw, 1); + mp_int *n = mp_make_sized(nw); + for (size_t i = 0; i < bytes.len; i++) + n->w[i / BIGNUM_INT_BYTES] |= + (BignumInt)(((const unsigned char *)bytes.ptr)[m*i+c]) << + (8 * (i % BIGNUM_INT_BYTES)); + return n; +} + +mp_int *mp_from_bytes_le(ptrlen bytes) +{ + return mp_from_bytes_int(bytes, 1, 0); +} + +mp_int *mp_from_bytes_be(ptrlen bytes) +{ + return mp_from_bytes_int(bytes, -1, bytes.len - 1); +} + +static mp_int *mp_from_words(size_t nw, const BignumInt *w) +{ + mp_int *x = mp_make_sized(nw); + memcpy(x->w, w, x->nw * sizeof(BignumInt)); + return x; +} + +/* + * Decimal-to-binary conversion: just go through the input string + * adding on the decimal value of each digit, and then multiplying the + * number so far by 10. + */ +mp_int *mp_from_decimal_pl(ptrlen decimal) +{ + /* 196/59 is an upper bound (and also a continued-fraction + * convergent) for log2(10), so this conservatively estimates the + * number of bits that will be needed to store any number that can + * be written in this many decimal digits. */ + assert(decimal.len < (~(size_t)0) / 196); + size_t bits = 196 * decimal.len / 59; + + /* Now round that up to words. */ + size_t words = bits / BIGNUM_INT_BITS + 1; + + mp_int *x = mp_make_sized(words); + for (size_t i = 0; i < decimal.len; i++) { + mp_add_integer_into(x, x, ((char *)decimal.ptr)[i] - '0'); + + if (i+1 == decimal.len) + break; + + mp_mul_integer_into(x, x, 10); + } + return x; +} + +mp_int *mp_from_decimal(const char *decimal) +{ + return mp_from_decimal_pl(ptrlen_from_asciz(decimal)); +} + +/* + * Hex-to-binary conversion: _algorithmically_ simpler than decimal + * (none of those multiplications by 10), but there's some fiddly + * bit-twiddling needed to process each hex digit without diverging + * control flow depending on whether it's a letter or a number. + */ +mp_int *mp_from_hex_pl(ptrlen hex) +{ + assert(hex.len <= (~(size_t)0) / 4); + size_t bits = hex.len * 4; + size_t words = (bits + BIGNUM_INT_BITS - 1) / BIGNUM_INT_BITS; + words = size_t_max(words, 1); + mp_int *x = mp_make_sized(words); + for (size_t nibble = 0; nibble < hex.len; nibble++) { + BignumInt digit = ((char *)hex.ptr)[hex.len-1 - nibble]; + + BignumInt lmask = ~-((BignumInt)((digit-'a')|('f'-digit)) + >> (BIGNUM_INT_BITS-1)); + BignumInt umask = ~-((BignumInt)((digit-'A')|('F'-digit)) + >> (BIGNUM_INT_BITS-1)); + + BignumInt digitval = digit - '0'; + digitval ^= (digitval ^ (digit - 'a' + 10)) & lmask; + digitval ^= (digitval ^ (digit - 'A' + 10)) & umask; + digitval &= 0xF; /* at least be _slightly_ nice about weird input */ + + size_t word_idx = nibble / (BIGNUM_INT_BYTES*2); + size_t nibble_within_word = nibble % (BIGNUM_INT_BYTES*2); + x->w[word_idx] |= digitval << (nibble_within_word * 4); + } + return x; +} + +mp_int *mp_from_hex(const char *hex) +{ + return mp_from_hex_pl(ptrlen_from_asciz(hex)); +} + +mp_int *mp_copy(mp_int *x) +{ + return mp_from_words(x->nw, x->w); +} + +uint8_t mp_get_byte(mp_int *x, size_t byte) +{ + return 0xFF & (mp_word(x, byte / BIGNUM_INT_BYTES) >> + (8 * (byte % BIGNUM_INT_BYTES))); +} + +unsigned mp_get_bit(mp_int *x, size_t bit) +{ + return 1 & (mp_word(x, bit / BIGNUM_INT_BITS) >> + (bit % BIGNUM_INT_BITS)); +} + +uintmax_t mp_get_integer(mp_int *x) +{ + uintmax_t toret = 0; + for (size_t i = x->nw; i-- > 0 ;) { + /* Shift in two stages to avoid undefined behaviour if the + * shift count equals the integer width */ + toret = (toret << (BIGNUM_INT_BITS/2)) << (BIGNUM_INT_BITS/2); + toret |= x->w[i]; + } + return toret; +} + +void mp_set_bit(mp_int *x, size_t bit, unsigned val) +{ + size_t word = bit / BIGNUM_INT_BITS; + assert(word < x->nw); + + unsigned shift = (bit % BIGNUM_INT_BITS); + + x->w[word] &= ~((BignumInt)1 << shift); + x->w[word] |= (BignumInt)(val & 1) << shift; +} + +/* + * Helper function used here and there to normalise any nonzero input + * value to 1. + */ +static inline unsigned normalise_to_1(BignumInt n) +{ + n = (n >> 1) | (n & 1); /* ensure top bit is clear */ + n = (BignumInt)(-n) >> (BIGNUM_INT_BITS - 1); /* normalise to 0 or 1 */ + return n; +} +static inline unsigned normalise_to_1_u64(uint64_t n) +{ + n = (n >> 1) | (n & 1); /* ensure top bit is clear */ + n = (-n) >> 63; /* normalise to 0 or 1 */ + return n; +} + +/* + * Find the highest nonzero word in a number. Returns the index of the + * word in x->w, and also a pair of output uint64_t in which that word + * appears in the high one shifted left by 'shift_wanted' bits, the + * words immediately below it occupy the space to the right, and the + * words below _that_ fill up the low one. + * + * If there is no nonzero word at all, the passed-by-reference output + * variables retain their original values. + */ +static inline void mp_find_highest_nonzero_word_pair( + mp_int *x, size_t shift_wanted, size_t *index, + uint64_t *hi, uint64_t *lo) +{ + uint64_t curr_hi = 0, curr_lo = 0; + + for (size_t curr_index = 0; curr_index < x->nw; curr_index++) { + BignumInt curr_word = x->w[curr_index]; + unsigned indicator = normalise_to_1(curr_word); + + curr_lo = (BIGNUM_INT_BITS < 64 ? (curr_lo >> BIGNUM_INT_BITS) : 0) | + (curr_hi << (64 - BIGNUM_INT_BITS)); + curr_hi = (BIGNUM_INT_BITS < 64 ? (curr_hi >> BIGNUM_INT_BITS) : 0) | + ((uint64_t)curr_word << shift_wanted); + + if (hi) *hi ^= (curr_hi ^ *hi ) & -(uint64_t)indicator; + if (lo) *lo ^= (curr_lo ^ *lo ) & -(uint64_t)indicator; + if (index) *index ^= (curr_index ^ *index) & -(size_t) indicator; + } +} + +size_t mp_get_nbits(mp_int *x) +{ + /* Sentinel values in case there are no bits set at all: we + * imagine that there's a word at position -1 (i.e. the topmost + * fraction word) which is all 1s, because that way, we handle a + * zero input by considering its highest set bit to be the top one + * of that word, i.e. just below the units digit, i.e. at bit + * index -1, i.e. so we'll return 0 on output. */ + size_t hiword_index = -(size_t)1; + uint64_t hiword64 = ~(BignumInt)0; + + /* + * Find the highest nonzero word and its index. + */ + mp_find_highest_nonzero_word_pair(x, 0, &hiword_index, &hiword64, NULL); + BignumInt hiword = hiword64; /* in case BignumInt is a narrower type */ + + /* + * Find the index of the highest set bit within hiword. + */ + BignumInt hibit_index = 0; + for (size_t i = (1 << (BIGNUM_INT_BITS_BITS-1)); i != 0; i >>= 1) { + BignumInt shifted_word = hiword >> i; + BignumInt indicator = + (BignumInt)(-shifted_word) >> (BIGNUM_INT_BITS-1); + hiword ^= (shifted_word ^ hiword ) & -indicator; + hibit_index += i & -(size_t)indicator; + } + + /* + * Put together the result. + */ + return (hiword_index << BIGNUM_INT_BITS_BITS) + hibit_index + 1; +} + +/* + * Shared code between the hex and decimal output functions to get rid + * of leading zeroes on the output string. The idea is that we wrote + * out a fixed number of digits and a trailing \0 byte into 'buf', and + * now we want to shift it all left so that the first nonzero digit + * moves to buf[0] (or, if there are no nonzero digits at all, we move + * up by 'maxtrim', so that we return 0 as "0" instead of ""). + */ +static void trim_leading_zeroes(char *buf, size_t bufsize, size_t maxtrim) +{ + size_t trim = maxtrim; + + /* + * Look for the first character not equal to '0', to find the + * shift count. + */ + if (trim > 0) { + for (size_t pos = trim; pos-- > 0 ;) { + uint8_t diff = buf[pos] ^ '0'; + size_t mask = -((((size_t)diff) - 1) >> (SIZE_T_BITS - 1)); + trim ^= (trim ^ pos) & ~mask; + } + } + + /* + * Now do the shift, in log n passes each of which does a + * conditional shift by 2^i bytes if bit i is set in the shift + * count. + */ + uint8_t *ubuf = (uint8_t *)buf; + for (size_t logd = 0; bufsize >> logd; logd++) { + uint8_t mask = -(uint8_t)((trim >> logd) & 1); + size_t d = (size_t)1 << logd; + for (size_t i = 0; i+d < bufsize; i++) { + uint8_t diff = mask & (ubuf[i] ^ ubuf[i+d]); + ubuf[i] ^= diff; + ubuf[i+d] ^= diff; + } + } +} + +/* + * Binary to decimal conversion. Our strategy here is to extract each + * decimal digit by finding the input number's residue mod 10, then + * subtract that off to give an exact multiple of 10, which then means + * you can safely divide by 10 by means of shifting right one bit and + * then multiplying by the inverse of 5 mod 2^n. + */ +char *mp_get_decimal(mp_int *x_orig) +{ + mp_int *x = mp_copy(x_orig), *y = mp_make_sized(x->nw); + + /* + * The inverse of 5 mod 2^lots is 0xccccccccccccccccccccd, for an + * appropriate number of 'c's. Manually construct an integer the + * right size. + */ + mp_int *inv5 = mp_make_sized(x->nw); + assert(BIGNUM_INT_BITS % 8 == 0); + for (size_t i = 0; i < inv5->nw; i++) + inv5->w[i] = BIGNUM_INT_MASK / 5 * 4; + inv5->w[0]++; + + /* + * 146/485 is an upper bound (and also a continued-fraction + * convergent) of log10(2), so this is a conservative estimate of + * the number of decimal digits needed to store a value that fits + * in this many binary bits. + */ + assert(x->nw < (~(size_t)1) / (146 * BIGNUM_INT_BITS)); + size_t bufsize = size_t_max(x->nw * (146 * BIGNUM_INT_BITS) / 485, 1) + 2; + char *outbuf = snewn(bufsize, char); + outbuf[bufsize - 1] = '\0'; + + /* + * Loop over the number generating digits from the least + * significant upwards, so that we write to outbuf in reverse + * order. + */ + for (size_t pos = bufsize - 1; pos-- > 0 ;) { + /* + * Find the current residue mod 10. We do this by first + * summing the bytes of the number, with all but the lowest + * one multiplied by 6 (because 256^i == 6 mod 10 for all + * i>0). That gives us a single word congruent mod 10 to the + * input number, and then we reduce it further by manual + * multiplication and shifting, just in case the compiler + * target implements the C division operator in a way that has + * input-dependent timing. + */ + uint32_t low_digit = 0, maxval = 0, mult = 1; + for (size_t i = 0; i < x->nw; i++) { + for (unsigned j = 0; j < BIGNUM_INT_BYTES; j++) { + low_digit += mult * (0xFF & (x->w[i] >> (8*j))); + maxval += mult * 0xFF; + mult = 6; + } + /* + * For _really_ big numbers, prevent overflow of t by + * periodically folding the top half of the accumulator + * into the bottom half, using the same rule 'multiply by + * 6 when shifting down by one or more whole bytes'. + */ + if (maxval > UINT32_MAX - (6 * 0xFF * BIGNUM_INT_BYTES)) { + low_digit = (low_digit & 0xFFFF) + 6 * (low_digit >> 16); + maxval = (maxval & 0xFFFF) + 6 * (maxval >> 16); + } + } + + /* + * Final reduction of low_digit. We multiply by 2^32 / 10 + * (that's the constant 0x19999999) to get a 64-bit value + * whose top 32 bits are the approximate quotient + * low_digit/10; then we subtract off 10 times that; and + * finally we do one last trial subtraction of 10 by adding 6 + * (which sets bit 4 if the number was just over 10) and then + * testing bit 4. + */ + low_digit -= 10 * ((0x19999999ULL * low_digit) >> 32); + low_digit -= 10 * ((low_digit + 6) >> 4); + + assert(low_digit < 10); /* make sure we did reduce fully */ + outbuf[pos] = '0' + low_digit; + + /* + * Now subtract off that digit, divide by 2 (using a right + * shift) and by 5 (using the modular inverse), to get the + * next output digit into the units position. + */ + mp_sub_integer_into(x, x, low_digit); + mp_rshift_fixed_into(y, x, 1); + mp_mul_into(x, y, inv5); + } + + mp_free(x); + mp_free(y); + mp_free(inv5); + + trim_leading_zeroes(outbuf, bufsize, bufsize - 2); + return outbuf; +} + +/* + * Binary to hex conversion. Reasonably simple (only a spot of bit + * twiddling to choose whether to output a digit or a letter for each + * nibble). + */ +static char *mp_get_hex_internal(mp_int *x, uint8_t letter_offset) +{ + size_t nibbles = x->nw * BIGNUM_INT_BYTES * 2; + size_t bufsize = nibbles + 1; + char *outbuf = snewn(bufsize, char); + outbuf[nibbles] = '\0'; + + for (size_t nibble = 0; nibble < nibbles; nibble++) { + size_t word_idx = nibble / (BIGNUM_INT_BYTES*2); + size_t nibble_within_word = nibble % (BIGNUM_INT_BYTES*2); + uint8_t digitval = 0xF & (x->w[word_idx] >> (nibble_within_word * 4)); + + uint8_t mask = -((digitval + 6) >> 4); + char digit = digitval + '0' + (letter_offset & mask); + outbuf[nibbles-1 - nibble] = digit; + } + + trim_leading_zeroes(outbuf, bufsize, nibbles - 1); + return outbuf; +} + +char *mp_get_hex(mp_int *x) +{ + return mp_get_hex_internal(x, 'a' - ('0'+10)); +} + +char *mp_get_hex_uppercase(mp_int *x) +{ + return mp_get_hex_internal(x, 'A' - ('0'+10)); +} + +/* + * Routines for reading and writing the SSH-1 and SSH-2 wire formats + * for multiprecision integers, declared in marshal.h. + * + * These can't avoid having control flow dependent on the true bit + * size of the number, because the wire format requires the number of + * output bytes to depend on that. + */ +void BinarySink_put_mp_ssh1(BinarySink *bs, mp_int *x) +{ + size_t bits = mp_get_nbits(x); + size_t bytes = (bits + 7) / 8; + + assert(bits < 0x10000); + put_uint16(bs, bits); + for (size_t i = bytes; i-- > 0 ;) + put_byte(bs, mp_get_byte(x, i)); +} + +void BinarySink_put_mp_ssh2(BinarySink *bs, mp_int *x) +{ + size_t bytes = (mp_get_nbits(x) + 8) / 8; + + put_uint32(bs, bytes); + for (size_t i = bytes; i-- > 0 ;) + put_byte(bs, mp_get_byte(x, i)); +} + +mp_int *BinarySource_get_mp_ssh1(BinarySource *src) +{ + unsigned bitc = get_uint16(src); + ptrlen bytes = get_data(src, (bitc + 7) / 8); + if (get_err(src)) { + return mp_from_integer(0); + } else { + mp_int *toret = mp_from_bytes_be(bytes); + /* SSH-1.5 spec says that it's OK for the prefix uint16 to be + * _greater_ than the actual number of bits */ + if (mp_get_nbits(toret) > bitc) { + src->err = BSE_INVALID; + mp_free(toret); + toret = mp_from_integer(0); + } + return toret; + } +} + +mp_int *BinarySource_get_mp_ssh2(BinarySource *src) +{ + ptrlen bytes = get_string(src); + if (get_err(src)) { + return mp_from_integer(0); + } else { + const unsigned char *p = bytes.ptr; + if ((bytes.len > 0 && + ((p[0] & 0x80) || + (p[0] == 0 && (bytes.len <= 1 || !(p[1] & 0x80)))))) { + src->err = BSE_INVALID; + return mp_from_integer(0); + } + return mp_from_bytes_be(bytes); + } +} + +/* + * Make an mp_int structure whose words array aliases a subinterval of + * some other mp_int. This makes it easy to read or write just the low + * or high words of a number, e.g. to add a number starting from a + * high bit position, or to reduce mod 2^{n*BIGNUM_INT_BITS}. + * + * The convention throughout this code is that when we store an mp_int + * directly by value, we always expect it to be an alias of some kind, + * so its words array won't ever need freeing. Whereas an 'mp_int *' + * has an owner, who knows whether it needs freeing or whether it was + * created by address-taking an alias. + */ +static mp_int mp_make_alias(mp_int *in, size_t offset, size_t len) +{ + /* + * Bounds-check the offset and length so that we always return + * something valid, even if it's not necessarily the length the + * caller asked for. + */ + if (offset > in->nw) + offset = in->nw; + if (len > in->nw - offset) + len = in->nw - offset; + + mp_int toret; + toret.nw = len; + toret.w = in->w + offset; + return toret; +} + +/* + * A special case of mp_make_alias: in some cases we preallocate a + * large mp_int to use as scratch space (to avoid pointless + * malloc/free churn in recursive or iterative work). + * + * mp_alloc_from_scratch creates an alias of size 'len' to part of + * 'pool', and adjusts 'pool' itself so that further allocations won't + * overwrite that space. + * + * There's no free function to go with this. Typically you just copy + * the pool mp_int by value, allocate from the copy, and when you're + * done with those allocations, throw the copy away and go back to the + * original value of pool. (A mark/release system.) + */ +static mp_int mp_alloc_from_scratch(mp_int *pool, size_t len) +{ + assert(len <= pool->nw); + mp_int toret = mp_make_alias(pool, 0, len); + *pool = mp_make_alias(pool, len, pool->nw); + return toret; +} + +/* + * Internal component common to lots of assorted add/subtract code. + * Reads words from a,b; writes into w_out (which might be NULL if the + * output isn't even needed). Takes an input carry flag in 'carry', + * and returns the output carry. Each word read from b is ANDed with + * b_and and then XORed with b_xor. + * + * So you can implement addition by setting b_and to all 1s and b_xor + * to 0; you can subtract by making b_xor all 1s too (effectively + * bit-flipping b) and also passing 1 as the input carry (to turn + * one's complement into two's complement). And you can do conditional + * add/subtract by choosing b_and to be all 1s or all 0s based on a + * condition, because the value of b will be totally ignored if b_and + * == 0. + */ +static BignumCarry mp_add_masked_into( + BignumInt *w_out, size_t rw, mp_int *a, mp_int *b, + BignumInt b_and, BignumInt b_xor, BignumCarry carry) +{ + for (size_t i = 0; i < rw; i++) { + BignumInt aword = mp_word(a, i), bword = mp_word(b, i), out; + bword = (bword & b_and) ^ b_xor; + BignumADC(out, carry, aword, bword, carry); + if (w_out) + w_out[i] = out; + } + return carry; +} + +/* + * Like the public mp_add_into except that it returns the output carry. + */ +static inline BignumCarry mp_add_into_internal(mp_int *r, mp_int *a, mp_int *b) +{ + return mp_add_masked_into(r->w, r->nw, a, b, ~(BignumInt)0, 0, 0); +} + +void mp_add_into(mp_int *r, mp_int *a, mp_int *b) +{ + mp_add_into_internal(r, a, b); +} + +void mp_sub_into(mp_int *r, mp_int *a, mp_int *b) +{ + mp_add_masked_into(r->w, r->nw, a, b, ~(BignumInt)0, ~(BignumInt)0, 1); +} + +void mp_and_into(mp_int *r, mp_int *a, mp_int *b) +{ + for (size_t i = 0; i < r->nw; i++) { + BignumInt aword = mp_word(a, i), bword = mp_word(b, i); + r->w[i] = aword & bword; + } +} + +void mp_or_into(mp_int *r, mp_int *a, mp_int *b) +{ + for (size_t i = 0; i < r->nw; i++) { + BignumInt aword = mp_word(a, i), bword = mp_word(b, i); + r->w[i] = aword | bword; + } +} + +void mp_xor_into(mp_int *r, mp_int *a, mp_int *b) +{ + for (size_t i = 0; i < r->nw; i++) { + BignumInt aword = mp_word(a, i), bword = mp_word(b, i); + r->w[i] = aword ^ bword; + } +} + +void mp_bic_into(mp_int *r, mp_int *a, mp_int *b) +{ + for (size_t i = 0; i < r->nw; i++) { + BignumInt aword = mp_word(a, i), bword = mp_word(b, i); + r->w[i] = aword & ~bword; + } +} + +static void mp_cond_negate(mp_int *r, mp_int *x, unsigned yes) +{ + BignumCarry carry = yes; + BignumInt flip = -(BignumInt)yes; + for (size_t i = 0; i < r->nw; i++) { + BignumInt xword = mp_word(x, i); + xword ^= flip; + BignumADC(r->w[i], carry, 0, xword, carry); + } +} + +/* + * Similar to mp_add_masked_into, but takes a C integer instead of an + * mp_int as the masked operand. + */ +static BignumCarry mp_add_masked_integer_into( + BignumInt *w_out, size_t rw, mp_int *a, uintmax_t b, + BignumInt b_and, BignumInt b_xor, BignumCarry carry) +{ + for (size_t i = 0; i < rw; i++) { + BignumInt aword = mp_word(a, i); + size_t shift = i * BIGNUM_INT_BITS; + BignumInt bword = shift < BIGNUM_INT_BYTES ? b >> shift : 0; + BignumInt out; + bword = (bword ^ b_xor) & b_and; + BignumADC(out, carry, aword, bword, carry); + if (w_out) + w_out[i] = out; + } + return carry; +} + +void mp_add_integer_into(mp_int *r, mp_int *a, uintmax_t n) +{ + mp_add_masked_integer_into(r->w, r->nw, a, n, ~(BignumInt)0, 0, 0); +} + +void mp_sub_integer_into(mp_int *r, mp_int *a, uintmax_t n) +{ + mp_add_masked_integer_into(r->w, r->nw, a, n, + ~(BignumInt)0, ~(BignumInt)0, 1); +} + +/* + * Sets r to a + n << (word_index * BIGNUM_INT_BITS), treating + * word_index as secret data. + */ +static void mp_add_integer_into_shifted_by_words( + mp_int *r, mp_int *a, uintmax_t n, size_t word_index) +{ + unsigned indicator = 0; + BignumCarry carry = 0; + + for (size_t i = 0; i < r->nw; i++) { + /* indicator becomes 1 when we reach the index that the least + * significant bits of n want to be placed at, and it stays 1 + * thereafter. */ + indicator |= 1 ^ normalise_to_1(i ^ word_index); + + /* If indicator is 1, we add the low bits of n into r, and + * shift n down. If it's 0, we add zero bits into r, and + * leave n alone. */ + BignumInt bword = n & -(BignumInt)indicator; + uintmax_t new_n = (BIGNUM_INT_BITS < 64 ? n >> BIGNUM_INT_BITS : 0); + n ^= (n ^ new_n) & -(uintmax_t)indicator; + + BignumInt aword = mp_word(a, i); + BignumInt out; + BignumADC(out, carry, aword, bword, carry); + r->w[i] = out; + } +} + +void mp_mul_integer_into(mp_int *r, mp_int *a, uint16_t n) +{ + BignumInt carry = 0, mult = n; + for (size_t i = 0; i < r->nw; i++) { + BignumInt aword = mp_word(a, i); + BignumMULADD(carry, r->w[i], aword, mult, carry); + } + assert(!carry); +} + +void mp_cond_add_into(mp_int *r, mp_int *a, mp_int *b, unsigned yes) +{ + BignumInt mask = -(BignumInt)(yes & 1); + mp_add_masked_into(r->w, r->nw, a, b, mask, 0, 0); +} + +void mp_cond_sub_into(mp_int *r, mp_int *a, mp_int *b, unsigned yes) +{ + BignumInt mask = -(BignumInt)(yes & 1); + mp_add_masked_into(r->w, r->nw, a, b, mask, mask, 1 & mask); +} + +/* + * Ordered comparison between unsigned numbers is done by subtracting + * one from the other and looking at the output carry. + */ +unsigned mp_cmp_hs(mp_int *a, mp_int *b) +{ + size_t rw = size_t_max(a->nw, b->nw); + return mp_add_masked_into(NULL, rw, a, b, ~(BignumInt)0, ~(BignumInt)0, 1); +} + +unsigned mp_hs_integer(mp_int *x, uintmax_t n) +{ + BignumInt carry = 1; + for (size_t i = 0; i < x->nw; i++) { + size_t shift = i * BIGNUM_INT_BITS; + BignumInt nword = shift < CHAR_BIT*sizeof(n) ? n >> shift : 0; + BignumInt dummy_out; + BignumADC(dummy_out, carry, x->w[i], ~nword, carry); + (void)dummy_out; + } + return carry; +} + +/* + * Equality comparison is done by bitwise XOR of the input numbers, + * ORing together all the output words, and normalising the result + * using our careful normalise_to_1 helper function. + */ +unsigned mp_cmp_eq(mp_int *a, mp_int *b) +{ + BignumInt diff = 0; + for (size_t i = 0, limit = size_t_max(a->nw, b->nw); i < limit; i++) + diff |= mp_word(a, i) ^ mp_word(b, i); + return 1 ^ normalise_to_1(diff); /* return 1 if diff _is_ zero */ +} + +unsigned mp_eq_integer(mp_int *x, uintmax_t n) +{ + BignumInt diff = 0; + for (size_t i = 0; i < x->nw; i++) { + size_t shift = i * BIGNUM_INT_BITS; + BignumInt nword = shift < CHAR_BIT*sizeof(n) ? n >> shift : 0; + diff |= x->w[i] ^ nword; + } + return 1 ^ normalise_to_1(diff); /* return 1 if diff _is_ zero */ +} + +void mp_neg_into(mp_int *r, mp_int *a) +{ + mp_int zero; + zero.nw = 0; + mp_sub_into(r, &zero, a); +} + +mp_int *mp_add(mp_int *x, mp_int *y) +{ + mp_int *r = mp_make_sized(size_t_max(x->nw, y->nw) + 1); + mp_add_into(r, x, y); + return r; +} + +mp_int *mp_sub(mp_int *x, mp_int *y) +{ + mp_int *r = mp_make_sized(size_t_max(x->nw, y->nw)); + mp_sub_into(r, x, y); + return r; +} + +mp_int *mp_neg(mp_int *a) +{ + mp_int *r = mp_make_sized(a->nw); + mp_neg_into(r, a); + return r; +} + +/* + * Internal routine: multiply and accumulate in the trivial O(N^2) + * way. Sets r <- r + a*b. + */ +static void mp_mul_add_simple(mp_int *r, mp_int *a, mp_int *b) +{ + BignumInt *aend = a->w + a->nw, *bend = b->w + b->nw, *rend = r->w + r->nw; + + for (BignumInt *ap = a->w, *rp = r->w; + ap < aend && rp < rend; ap++, rp++) { + + BignumInt adata = *ap, carry = 0, *rq = rp; + + for (BignumInt *bp = b->w; bp < bend && rq < rend; bp++, rq++) { + BignumInt bdata = bp < bend ? *bp : 0; + BignumMULADD2(carry, *rq, adata, bdata, *rq, carry); + } + + for (; rq < rend; rq++) + BignumADC(*rq, carry, carry, *rq, 0); + } +} + +#ifndef KARATSUBA_THRESHOLD /* allow redefinition via -D for testing */ +#define KARATSUBA_THRESHOLD 24 +#endif + +static inline size_t mp_mul_scratchspace_unary(size_t n) +{ + /* + * Simplistic and overcautious bound on the amount of scratch + * space that the recursive multiply function will need. + * + * The rationale is: on the main Karatsuba branch of + * mp_mul_internal, which is the most space-intensive one, we + * allocate space for (a0+a1) and (b0+b1) (each just over half the + * input length n) and their product (the sum of those sizes, i.e. + * just over n itself). Then in order to actually compute the + * product, we do a recursive multiplication of size just over n. + * + * If all those 'just over' weren't there, and everything was + * _exactly_ half the length, you'd get the amount of space for a + * size-n multiply defined by the recurrence M(n) = 2n + M(n/2), + * which is satisfied by M(n) = 4n. But instead it's (2n plus a + * word or two) and M(n/2 plus a word or two). On the assumption + * that there's still some constant k such that M(n) <= kn, this + * gives us kn = 2n + w + k(n/2 + w), where w is a small constant + * (one or two words). That simplifies to kn/2 = 2n + (k+1)w, and + * since we don't even _start_ needing scratch space until n is at + * least 50, we can bound 2n + (k+1)w above by 3n, giving k=6. + * + * So I claim that 6n words of scratch space will suffice, and I + * check that by assertion at every stage of the recursion. + */ + return n * 6; +} + +static size_t mp_mul_scratchspace(size_t rw, size_t aw, size_t bw) +{ + size_t inlen = size_t_min(rw, size_t_max(aw, bw)); + return mp_mul_scratchspace_unary(inlen); +} + +static void mp_mul_internal(mp_int *r, mp_int *a, mp_int *b, mp_int scratch) +{ + size_t inlen = size_t_min(r->nw, size_t_max(a->nw, b->nw)); + assert(scratch.nw >= mp_mul_scratchspace_unary(inlen)); + + mp_clear(r); + + if (inlen < KARATSUBA_THRESHOLD || a->nw == 0 || b->nw == 0) { + /* + * The input numbers are too small to bother optimising. Go + * straight to the simple primitive approach. + */ + mp_mul_add_simple(r, a, b); + return; + } + + /* + * Karatsuba divide-and-conquer algorithm. We cut each input in + * half, so that it's expressed as two big 'digits' in a giant + * base D: + * + * a = a_1 D + a_0 + * b = b_1 D + b_0 + * + * Then the product is of course + * + * ab = a_1 b_1 D^2 + (a_1 b_0 + a_0 b_1) D + a_0 b_0 + * + * and we compute the three coefficients by recursively calling + * ourself to do half-length multiplications. + * + * The clever bit that makes this worth doing is that we only need + * _one_ half-length multiplication for the central coefficient + * rather than the two that it obviouly looks like, because we can + * use a single multiplication to compute + * + * (a_1 + a_0) (b_1 + b_0) = a_1 b_1 + a_1 b_0 + a_0 b_1 + a_0 b_0 + * + * and then we subtract the other two coefficients (a_1 b_1 and + * a_0 b_0) which we were computing anyway. + * + * Hence we get to multiply two numbers of length N in about three + * times as much work as it takes to multiply numbers of length + * N/2, which is obviously better than the four times as much work + * it would take if we just did a long conventional multiply. + */ + + /* Break up the input as botlen + toplen, with botlen >= toplen. + * The 'base' D is equal to 2^{botlen * BIGNUM_INT_BITS}. */ + size_t toplen = inlen / 2; + size_t botlen = inlen - toplen; + + /* Alias bignums that address the two halves of a,b, and useful + * pieces of r. */ + mp_int a0 = mp_make_alias(a, 0, botlen); + mp_int b0 = mp_make_alias(b, 0, botlen); + mp_int a1 = mp_make_alias(a, botlen, toplen); + mp_int b1 = mp_make_alias(b, botlen, toplen); + mp_int r0 = mp_make_alias(r, 0, botlen*2); + mp_int r1 = mp_make_alias(r, botlen, r->nw); + mp_int r2 = mp_make_alias(r, botlen*2, r->nw); + + /* Recurse to compute a0*b0 and a1*b1, in their correct positions + * in the output bignum. They can't overlap. */ + mp_mul_internal(&r0, &a0, &b0, scratch); + mp_mul_internal(&r2, &a1, &b1, scratch); + + if (r->nw < inlen*2) { + /* + * The output buffer isn't large enough to require the whole + * product, so some of a1*b1 won't have been stored. In that + * case we won't try to do the full Karatsuba optimisation; + * we'll just recurse again to compute a0*b1 and a1*b0 - or at + * least as much of them as the output buffer size requires - + * and add each one in. + */ + mp_int s = mp_alloc_from_scratch( + &scratch, size_t_min(botlen+toplen, r1.nw)); + + mp_mul_internal(&s, &a0, &b1, scratch); + mp_add_into(&r1, &r1, &s); + mp_mul_internal(&s, &a1, &b0, scratch); + mp_add_into(&r1, &r1, &s); + return; + } + + /* a0+a1 and b0+b1 */ + mp_int asum = mp_alloc_from_scratch(&scratch, botlen+1); + mp_int bsum = mp_alloc_from_scratch(&scratch, botlen+1); + mp_add_into(&asum, &a0, &a1); + mp_add_into(&bsum, &b0, &b1); + + /* Their product */ + mp_int product = mp_alloc_from_scratch(&scratch, botlen*2+1); + mp_mul_internal(&product, &asum, &bsum, scratch); + + /* Subtract off the outer terms we already have */ + mp_sub_into(&product, &product, &r0); + mp_sub_into(&product, &product, &r2); + + /* And add it in with the right offset. */ + mp_add_into(&r1, &r1, &product); +} + +void mp_mul_into(mp_int *r, mp_int *a, mp_int *b) +{ + mp_int *scratch = mp_make_sized(mp_mul_scratchspace(r->nw, a->nw, b->nw)); + mp_mul_internal(r, a, b, *scratch); + mp_free(scratch); +} + +mp_int *mp_mul(mp_int *x, mp_int *y) +{ + mp_int *r = mp_make_sized(x->nw + y->nw); + mp_mul_into(r, x, y); + return r; +} + +void mp_lshift_fixed_into(mp_int *r, mp_int *a, size_t bits) +{ + size_t words = bits / BIGNUM_INT_BITS; + size_t bitoff = bits % BIGNUM_INT_BITS; + + for (size_t i = r->nw; i-- > 0 ;) { + if (i < words) { + r->w[i] = 0; + } else { + r->w[i] = mp_word(a, i - words); + if (bitoff != 0) { + r->w[i] <<= bitoff; + if (i > words) + r->w[i] |= mp_word(a, i - words - 1) >> + (BIGNUM_INT_BITS - bitoff); + } + } + } +} + +void mp_rshift_fixed_into(mp_int *r, mp_int *a, size_t bits) +{ + size_t words = bits / BIGNUM_INT_BITS; + size_t bitoff = bits % BIGNUM_INT_BITS; + + for (size_t i = 0; i < r->nw; i++) { + r->w[i] = mp_word(a, i + words); + if (bitoff != 0) { + r->w[i] >>= bitoff; + r->w[i] |= mp_word(a, i + words + 1) << (BIGNUM_INT_BITS - bitoff); + } + } +} + +mp_int *mp_rshift_fixed(mp_int *x, size_t bits) +{ + size_t words = bits / BIGNUM_INT_BITS; + size_t nw = x->nw - size_t_min(x->nw, words); + mp_int *r = mp_make_sized(size_t_max(nw, 1)); + mp_rshift_fixed_into(r, x, bits); + return r; +} + +/* + * Safe right shift is done using the same technique as + * trim_leading_zeroes above: you make an n-word left shift by + * composing an appropriate subset of power-of-2-sized shifts, so it + * takes log_2(n) loop iterations each of which does a different shift + * by a power of 2 words, using the usual bit twiddling to make the + * whole shift conditional on the appropriate bit of n. + */ +mp_int *mp_rshift_safe(mp_int *x, size_t bits) +{ + size_t wordshift = bits / BIGNUM_INT_BITS; + size_t bitshift = bits % BIGNUM_INT_BITS; + + mp_int *r = mp_copy(x); + + unsigned clear = (r->nw - wordshift) >> (CHAR_BIT * sizeof(size_t) - 1); + mp_cond_clear(r, clear); + + for (unsigned bit = 0; r->nw >> bit; bit++) { + size_t word_offset = 1 << bit; + BignumInt mask = -(BignumInt)((wordshift >> bit) & 1); + for (size_t i = 0; i < r->nw; i++) { + BignumInt w = mp_word(r, i + word_offset); + r->w[i] ^= (r->w[i] ^ w) & mask; + } + } + + /* + * That's done the shifting by words; now we do the shifting by + * bits. + */ + for (unsigned bit = 0; bit < BIGNUM_INT_BITS_BITS; bit++) { + unsigned shift = 1 << bit, upshift = BIGNUM_INT_BITS - shift; + BignumInt mask = -(BignumInt)((bitshift >> bit) & 1); + for (size_t i = 0; i < r->nw; i++) { + BignumInt w = ((r->w[i] >> shift) | (mp_word(r, i+1) << upshift)); + r->w[i] ^= (r->w[i] ^ w) & mask; + } + } + + return r; +} + +void mp_reduce_mod_2to(mp_int *x, size_t p) +{ + size_t word = p / BIGNUM_INT_BITS; + size_t mask = ((size_t)1 << (p % BIGNUM_INT_BITS)) - 1; + for (; word < x->nw; word++) { + x->w[word] &= mask; + mask = 0; + } +} + +/* + * Inverse mod 2^n is computed by an iterative technique which doubles + * the number of bits at each step. + */ +mp_int *mp_invert_mod_2to(mp_int *x, size_t p) +{ + /* Input checks: x must be coprime to the modulus, i.e. odd, and p + * can't be zero */ + assert(x->nw > 0); + assert(x->w[0] & 1); + assert(p > 0); + + size_t rw = (p + BIGNUM_INT_BITS - 1) / BIGNUM_INT_BITS; + rw = size_t_max(rw, 1); + mp_int *r = mp_make_sized(rw); + + size_t mul_scratchsize = mp_mul_scratchspace(2*rw, rw, rw); + mp_int *scratch_orig = mp_make_sized(6 * rw + mul_scratchsize); + mp_int scratch_per_iter = *scratch_orig; + mp_int mul_scratch = mp_alloc_from_scratch( + &scratch_per_iter, mul_scratchsize); + + r->w[0] = 1; + + for (size_t b = 1; b < p; b <<= 1) { + /* + * In each step of this iteration, we have the inverse of x + * mod 2^b, and we want the inverse of x mod 2^{2b}. + * + * Write B = 2^b for convenience, so we want x^{-1} mod B^2. + * Let x = x_0 + B x_1 + k B^2, with 0 <= x_0,x_1 < B. + * + * We want to find r_0 and r_1 such that + * (r_1 B + r_0) (x_1 B + x_0) == 1 (mod B^2) + * + * To begin with, we know r_0 must be the inverse mod B of + * x_0, i.e. of x, i.e. it is the inverse we computed in the + * previous iteration. So now all we need is r_1. + * + * Multiplying out, neglecting multiples of B^2, and writing + * x_0 r_0 = K B + 1, we have + * + * r_1 x_0 B + r_0 x_1 B + K B == 0 (mod B^2) + * => r_1 x_0 B == - r_0 x_1 B - K B (mod B^2) + * => r_1 x_0 == - r_0 x_1 - K (mod B) + * => r_1 == r_0 (- r_0 x_1 - K) (mod B) + * + * (the last step because we multiply through by the inverse + * of x_0, which we already know is r_0). + */ + + mp_int scratch_this_iter = scratch_per_iter; + size_t Bw = (b + BIGNUM_INT_BITS - 1) / BIGNUM_INT_BITS; + size_t B2w = (2*b + BIGNUM_INT_BITS - 1) / BIGNUM_INT_BITS; + + /* Start by finding K: multiply x_0 by r_0, and shift down. */ + mp_int x0 = mp_alloc_from_scratch(&scratch_this_iter, Bw); + mp_copy_into(&x0, x); + mp_reduce_mod_2to(&x0, b); + mp_int r0 = mp_make_alias(r, 0, Bw); + mp_int Kshift = mp_alloc_from_scratch(&scratch_this_iter, B2w); + mp_mul_internal(&Kshift, &x0, &r0, mul_scratch); + mp_int K = mp_alloc_from_scratch(&scratch_this_iter, Bw); + mp_rshift_fixed_into(&K, &Kshift, b); + + /* Now compute the product r_0 x_1, reusing the space of Kshift. */ + mp_int x1 = mp_alloc_from_scratch(&scratch_this_iter, Bw); + mp_rshift_fixed_into(&x1, x, b); + mp_reduce_mod_2to(&x1, b); + mp_int r0x1 = mp_make_alias(&Kshift, 0, Bw); + mp_mul_internal(&r0x1, &r0, &x1, mul_scratch); + + /* Add K to that. */ + mp_add_into(&r0x1, &r0x1, &K); + + /* Negate it. */ + mp_neg_into(&r0x1, &r0x1); + + /* Multiply by r_0. */ + mp_int r1 = mp_alloc_from_scratch(&scratch_this_iter, Bw); + mp_mul_internal(&r1, &r0, &r0x1, mul_scratch); + mp_reduce_mod_2to(&r1, b); + + /* That's our r_1, so add it on to r_0 to get the full inverse + * output from this iteration. */ + mp_lshift_fixed_into(&K, &r1, (b % BIGNUM_INT_BITS)); + size_t Bpos = b / BIGNUM_INT_BITS; + mp_int r1_position = mp_make_alias(r, Bpos, B2w-Bpos); + mp_add_into(&r1_position, &r1_position, &K); + } + + /* Finally, reduce mod the precise desired number of bits. */ + mp_reduce_mod_2to(r, p); + + mp_free(scratch_orig); + return r; +} + +static size_t monty_scratch_size(MontyContext *mc) +{ + return 3*mc->rw + mc->pw + mp_mul_scratchspace(mc->pw, mc->rw, mc->rw); +} + +MontyContext *monty_new(mp_int *modulus) +{ + MontyContext *mc = snew(MontyContext); + + mc->rw = modulus->nw; + mc->rbits = mc->rw * BIGNUM_INT_BITS; + mc->pw = mc->rw * 2 + 1; + + mc->m = mp_copy(modulus); + + mc->minus_minv_mod_r = mp_invert_mod_2to(mc->m, mc->rbits); + mp_neg_into(mc->minus_minv_mod_r, mc->minus_minv_mod_r); + + mp_int *r = mp_make_sized(mc->rw + 1); + r->w[mc->rw] = 1; + mc->powers_of_r_mod_m[0] = mp_mod(r, mc->m); + mp_free(r); + + for (size_t j = 1; j < lenof(mc->powers_of_r_mod_m); j++) + mc->powers_of_r_mod_m[j] = mp_modmul( + mc->powers_of_r_mod_m[0], mc->powers_of_r_mod_m[j-1], mc->m); + + mc->scratch = mp_make_sized(monty_scratch_size(mc)); + + return mc; +} + +void monty_free(MontyContext *mc) +{ + mp_free(mc->m); + for (size_t j = 0; j < 3; j++) + mp_free(mc->powers_of_r_mod_m[j]); + mp_free(mc->minus_minv_mod_r); + mp_free(mc->scratch); + smemclr(mc, sizeof(*mc)); + sfree(mc); +} + +/* + * The main Montgomery reduction step. + */ +static mp_int monty_reduce_internal(MontyContext *mc, mp_int *x, mp_int scratch) +{ + /* + * The trick with Montgomery reduction is that on the one hand we + * want to reduce the size of the input by a factor of about r, + * and on the other hand, the two numbers we just multiplied were + * both stored with an extra factor of r multiplied in. So we + * computed ar*br = ab r^2, but we want to return abr, so we need + * to divide by r - and if we can do that by _actually dividing_ + * by r then this also reduces the size of the number. + * + * But we can only do that if the number we're dividing by r is a + * multiple of r. So first we must add an adjustment to it which + * clears its bottom 'rbits' bits. That adjustment must be a + * multiple of m in order to leave the residue mod n unchanged, so + * the question is, what multiple of m can we add to x to make it + * congruent to 0 mod r? And the answer is, x * (-m)^{-1} mod r. + */ + + /* x mod r */ + mp_int x_lo = mp_make_alias(x, 0, mc->rbits); + + /* x * (-m)^{-1}, i.e. the number we want to multiply by m */ + mp_int k = mp_alloc_from_scratch(&scratch, mc->rw); + mp_mul_internal(&k, &x_lo, mc->minus_minv_mod_r, scratch); + + /* m times that, i.e. the number we want to add to x */ + mp_int mk = mp_alloc_from_scratch(&scratch, mc->pw); + mp_mul_internal(&mk, mc->m, &k, scratch); + + /* Add it to x */ + mp_add_into(&mk, x, &mk); + + /* Reduce mod r, by simply making an alias to the upper words of x */ + mp_int toret = mp_make_alias(&mk, mc->rw, mk.nw - mc->rw); + + /* + * We'll generally be doing this after a multiplication of two + * fully reduced values. So our input could be anything up to m^2, + * and then we added up to rm to it. Hence, the maximum value is + * rm+m^2, and after dividing by r, that becomes r + m(m/r) < 2r. + * So a single trial-subtraction will finish reducing to the + * interval [0,m). + */ + mp_cond_sub_into(&toret, &toret, mc->m, mp_cmp_hs(&toret, mc->m)); + return toret; +} + +void monty_mul_into(MontyContext *mc, mp_int *r, mp_int *x, mp_int *y) +{ + assert(x->nw <= mc->rw); + assert(y->nw <= mc->rw); + + mp_int scratch = *mc->scratch; + mp_int tmp = mp_alloc_from_scratch(&scratch, 2*mc->rw); + mp_mul_into(&tmp, x, y); + mp_int reduced = monty_reduce_internal(mc, &tmp, scratch); + mp_copy_into(r, &reduced); + mp_clear(mc->scratch); +} + +mp_int *monty_mul(MontyContext *mc, mp_int *x, mp_int *y) +{ + mp_int *toret = mp_make_sized(mc->rw); + monty_mul_into(mc, toret, x, y); + return toret; +} + +mp_int *monty_modulus(MontyContext *mc) +{ + return mc->m; +} + +mp_int *monty_identity(MontyContext *mc) +{ + return mc->powers_of_r_mod_m[0]; +} + +mp_int *monty_invert(MontyContext *mc, mp_int *x) +{ + /* Given xr, we want to return x^{-1}r = (xr)^{-1} r^2 = + * monty_reduce((xr)^{-1} r^3) */ + mp_int *tmp = mp_invert(x, mc->m); + mp_int *toret = monty_mul(mc, tmp, mc->powers_of_r_mod_m[2]); + mp_free(tmp); + return toret; +} + +/* + * Importing a number into Montgomery representation involves + * multiplying it by r and reducing mod m. We use the general-purpose + * mp_modmul for this, in case the input number is out of range. + */ +mp_int *monty_import(MontyContext *mc, mp_int *x) +{ + return mp_modmul(x, mc->powers_of_r_mod_m[0], mc->m); +} + +void monty_import_into(MontyContext *mc, mp_int *r, mp_int *x) +{ + mp_int *imported = monty_import(mc, x); + mp_copy_into(r, imported); + mp_free(imported); +} + +/* + * Exporting a number means multiplying it by r^{-1}, which is exactly + * what monty_reduce does anyway, so we just do that. + */ +void monty_export_into(MontyContext *mc, mp_int *r, mp_int *x) +{ + assert(x->nw <= 2*mc->rw); + mp_int reduced = monty_reduce_internal(mc, x, *mc->scratch); + mp_copy_into(r, &reduced); + mp_clear(mc->scratch); +} + +mp_int *monty_export(MontyContext *mc, mp_int *x) +{ + mp_int *toret = mp_make_sized(mc->rw); + monty_export_into(mc, toret, x); + return toret; +} + +static void monty_reduce(MontyContext *mc, mp_int *x) +{ + mp_int reduced = monty_reduce_internal(mc, x, *mc->scratch); + mp_copy_into(x, &reduced); + mp_clear(mc->scratch); +} + +mp_int *monty_pow(MontyContext *mc, mp_int *base, mp_int *exponent) +{ + /* square builds up powers of the form base^{2^i}. */ + mp_int *square = mp_copy(base); + size_t i = 0; + + /* out accumulates the output value. Starts at 1 (in Montgomery + * representation) and we multiply in each base^{2^i}. */ + mp_int *out = mp_copy(mc->powers_of_r_mod_m[0]); + + /* tmp holds each product we compute and reduce. */ + mp_int *tmp = mp_make_sized(mc->rw * 2); + + while (true) { + mp_mul_into(tmp, out, square); + monty_reduce(mc, tmp); + mp_select_into(out, out, tmp, mp_get_bit(exponent, i)); + + if (++i >= exponent->nw * BIGNUM_INT_BITS) + break; + + mp_mul_into(tmp, square, square); + monty_reduce(mc, tmp); + mp_copy_into(square, tmp); + } + + mp_free(square); + mp_free(tmp); + mp_clear(mc->scratch); + return out; +} + +mp_int *mp_modpow(mp_int *base, mp_int *exponent, mp_int *modulus) +{ + assert(modulus->nw > 0); + assert(modulus->w[0] & 1); + + MontyContext *mc = monty_new(modulus); + mp_int *m_base = monty_import(mc, base); + mp_int *m_out = monty_pow(mc, m_base, exponent); + mp_int *out = monty_export(mc, m_out); + mp_free(m_base); + mp_free(m_out); + monty_free(mc); + return out; +} + +/* + * Given two coprime nonzero input integers a,b, returns two integers + * A,B such that A*a - B*b = 1. A,B will be the minimal non-negative + * pair satisfying that criterion, which is equivalent to saying that + * 0<=Ab, and gcd(a,b) = + * gcd(b,(a-b)/2). + * + * For this application, I always expect the actual gcd to be coprime, + * so we can rule out the 'both even' initial case. So this function + * just performs a sequence of reductions in the following form: + * + * - if a,b are both odd, sort them so that a > b, and replace a with + * b-a; otherwise sort them so that a is the even one + * - either way, now a is even and b is odd, so divide a by 2. + * + * The big change to Stein's algorithm is that we need the Bezout + * coefficients as output, not just the gcd. So we need to know how to + * generate those in each case, based on the coefficients from the + * reduced pair of numbers: + * + * - If a is even, and u,v are such that u*(a/2) + v*b = 1: + * + if u is also even, then this is just (u/2)*a + v*b = 1 + * + otherwise, (u+b)*(a/2) + (v-a/2)*b is also equal to 1, and + * since u and b are both odd, (u+b)/2 is an integer, so we have + * ((u+b)/2)*a + (v-a/2)*b = 1. + * + * - If a,b are both odd, and u,v are such that u*b + v*(a-b) = 1, + * then v*a + (u-v)*b = 1. + * + * In the case where we passed from (a,b) to (b,(a-b)/2), we regard it + * as having first subtracted b from a and then halved a, so both of + * these transformations must be done in sequence. + * + * The code below transforms this from a recursive to an iterative + * algorithm. We first reduce a,b to 0,1, recording at each stage + * whether we did the initial subtraction, and whether we had to swap + * the two values; then we iterate backwards over that record of what + * we did, applying the above rules for building up the Bezout + * coefficients as we go. Of course, all the case analysis is done by + * the usual bit-twiddling conditionalisation to avoid data-dependent + * control flow. + * + * Also, since these mp_ints are generally treated as unsigned, we + * store the coefficients by absolute value, with the semantics that + * they always have opposite sign, and in the unwinding loop we keep a + * bit indicating whether Aa-Bb is currently expected to be +1 or -1, + * so that we can do one final conditional adjustment if it's -1. + * + * Once the reduction rules have managed to reduce the input numbers + * to (0,1), then they are stable (the next reduction will always + * divide the even one by 2, which maps 0 to 0). So it doesn't matter + * if we do more steps of the algorithm than necessary; hence, for + * constant time, we just need to find the maximum number we could + * _possibly_ require, and do that many. + * + * If a,b < 2^n, at most 2n iterations are required. Proof: consider + * the quantity Q = log_2(a) + log_2(b). Every step halves one of the + * numbers (and may also reduce one of them further by doing a + * subtraction beforehand, but in the worst case, not by much or not + * at all). So Q reduces by at least 1 per iteration, and it starts + * off with a value at most 2n. + * + * The worst case inputs (I think) are where x=2^{n-1} and y=2^n-1 + * (i.e. x is a power of 2 and y is all 1s). In that situation, the + * first n-1 steps repeatedly halve x until it's 1, and then there are + * n further steps each of which subtracts 1 from y and halves it. + */ +static void mp_bezout_into(mp_int *a_coeff_out, mp_int *b_coeff_out, + mp_int *a_in, mp_int *b_in) +{ + size_t nw = size_t_max(1, size_t_max(a_in->nw, b_in->nw)); + + /* Make mutable copies of the input numbers */ + mp_int *a = mp_make_sized(nw), *b = mp_make_sized(nw); + mp_copy_into(a, a_in); + mp_copy_into(b, b_in); + + /* Space to build up the output coefficients, with an extra word + * so that intermediate values can overflow off the top and still + * right-shift back down to the correct value */ + mp_int *ac = mp_make_sized(nw + 1), *bc = mp_make_sized(nw + 1); + + /* And a general-purpose temp register */ + mp_int *tmp = mp_make_sized(nw); + + /* Space to record the sequence of reduction steps to unwind. We + * make it a BignumInt for no particular reason except that (a) + * mp_make_sized conveniently zeroes the allocation and mp_free + * wipes it, and (b) this way I can use mp_dump() if I have to + * debug this code. */ + size_t steps = 2 * nw * BIGNUM_INT_BITS; + mp_int *record = mp_make_sized( + (steps*2 + BIGNUM_INT_BITS - 1) / BIGNUM_INT_BITS); + + for (size_t step = 0; step < steps; step++) { + /* + * If a and b are both odd, we want to sort them so that a is + * larger. But if one is even, we want to sort them so that a + * is the even one. + */ + unsigned swap_if_both_odd = mp_cmp_hs(b, a); + unsigned swap_if_one_even = a->w[0] & 1; + unsigned both_odd = a->w[0] & b->w[0] & 1; + unsigned swap = swap_if_one_even ^ ( + (swap_if_both_odd ^ swap_if_one_even) & both_odd); + + mp_cond_swap(a, b, swap); + + /* + * If a,b are both odd, then a is the larger number, so + * subtract the smaller one from it. + */ + mp_cond_sub_into(a, a, b, both_odd); + + /* + * Now a is even, so divide it by two. + */ + mp_rshift_fixed_into(a, a, 1); + + /* + * Record the two 1-bit values both_odd and swap. + */ + mp_set_bit(record, step*2, both_odd); + mp_set_bit(record, step*2+1, swap); + } + + /* + * Now we expect to have reduced the two numbers to 0 and 1, + * although we don't know which way round. (But we avoid checking + * this by assertion; sometimes we'll need to do this computation + * without giving away that we already know the inputs were bogus. + * So we'd prefer to just press on and return nonsense.) + */ + + /* + * So their Bezout coefficients at this point are simply + * themselves. + */ + mp_copy_into(ac, a); + mp_copy_into(bc, b); + + /* + * We'll maintain the invariant as we unwind that ac * a - bc * b + * is either +1 or -1, and we'll remember which. (We _could_ keep + * it at +1 the whole time, but it would cost more work every time + * round the loop, so it's cheaper to fix that up once at the + * end.) + * + * Initially, the result is +1 if a was the nonzero value after + * reduction, and -1 if b was. + */ + unsigned minus_one = b->w[0]; + + for (size_t step = steps; step-- > 0 ;) { + /* + * Recover the data from the step we're unwinding. + */ + unsigned both_odd = mp_get_bit(record, step*2); + unsigned swap = mp_get_bit(record, step*2+1); + + /* + * Unwind the division: if our coefficient of a is odd, we + * adjust the coefficients by +b and +a respectively. + */ + unsigned adjust = ac->w[0] & 1; + mp_cond_add_into(ac, ac, b, adjust); + mp_cond_add_into(bc, bc, a, adjust); + + /* + * Now ac is definitely even, so we divide it by two. + */ + mp_rshift_fixed_into(ac, ac, 1); + + /* + * Now unwind the subtraction, if there was one, by adding + * ac to bc. + */ + mp_cond_add_into(bc, bc, ac, both_odd); + + /* + * Undo the transformation of the input numbers, by + * multiplying a by 2 and then adding b to a (the latter + * only if both_odd). + */ + mp_lshift_fixed_into(a, a, 1); + mp_cond_add_into(a, a, b, both_odd); + + /* + * Finally, undo the swap. If we do swap, this also + * reverses the sign of the current result ac*a+bc*b. + */ + mp_cond_swap(a, b, swap); + mp_cond_swap(ac, bc, swap); + minus_one ^= swap; + } + + /* + * Now we expect to have recovered the input a,b. + */ + assert(mp_cmp_eq(a, a_in) & mp_cmp_eq(b, b_in)); + + /* + * But we might find that our current result is -1 instead of +1, + * that is, we have A',B' such that A'a - B'b = -1. + * + * In that situation, we set A = b-A' and B = a-B', giving us + * Aa-Bb = ab - A'a - ab + B'b = +1. + */ + mp_sub_into(tmp, b, ac); + mp_select_into(ac, ac, tmp, minus_one); + mp_sub_into(tmp, a, bc); + mp_select_into(bc, bc, tmp, minus_one); + + /* + * Now we really are done. Return the outputs. + */ + if (a_coeff_out) + mp_copy_into(a_coeff_out, ac); + if (b_coeff_out) + mp_copy_into(b_coeff_out, bc); + + mp_free(a); + mp_free(b); + mp_free(ac); + mp_free(bc); + mp_free(tmp); + mp_free(record); +} + +mp_int *mp_invert(mp_int *x, mp_int *m) +{ + mp_int *result = mp_make_sized(m->nw); + mp_bezout_into(result, NULL, x, m); + return result; +} + +static uint32_t recip_approx_32(uint32_t x) +{ + /* + * Given an input x in [2^31,2^32), i.e. a uint32_t with its high + * bit set, this function returns an approximation to 2^63/x, + * computed using only multiplications and bit shifts just in case + * the C divide operator has non-constant time (either because the + * underlying machine instruction does, or because the operator + * expands to a library function on a CPU without hardware + * division). + * + * The coefficients are derived from those of the degree-9 + * polynomial which is the minimax-optimal approximation to that + * function on the given interval (generated using the Remez + * algorithm), converted into integer arithmetic with shifts used + * to maximise the number of significant bits at every state. (A + * sort of 'static floating point' - the exponent is statically + * known at every point in the code, so it never needs to be + * stored at run time or to influence runtime decisions.) + * + * Exhaustive iteration over the whole input space shows the + * largest possible error to be 1686.54. (The input value + * attaining that bound is 4226800006 == 0xfbefd986, whose true + * reciprocal is 2182116973.540... == 0x8210766d.8a6..., whereas + * this function returns 2182115287 == 0x82106fd7.) + */ + uint64_t r = 0x92db03d6ULL; + r = 0xf63e71eaULL - ((r*x) >> 34); + r = 0xb63721e8ULL - ((r*x) >> 34); + r = 0x9c2da00eULL - ((r*x) >> 33); + r = 0xaada0bb8ULL - ((r*x) >> 32); + r = 0xf75cd403ULL - ((r*x) >> 31); + r = 0xecf97a41ULL - ((r*x) >> 31); + r = 0x90d876cdULL - ((r*x) >> 31); + r = 0x6682799a0ULL - ((r*x) >> 26); + return r; +} + +void mp_divmod_into(mp_int *n, mp_int *d, mp_int *q_out, mp_int *r_out) +{ + assert(!mp_eq_integer(d, 0)); + + /* + * We do division by using Newton-Raphson iteration to converge to + * the reciprocal of d (or rather, R/d for R a sufficiently large + * power of 2); then we multiply that reciprocal by n; and we + * finish up with conditional subtraction. + * + * But we have to do it in a fixed number of N-R iterations, so we + * need some error analysis to know how many we might need. + * + * The iteration is derived by defining f(r) = d - R/r. + * Differentiating gives f'(r) = R/r^2, and the Newton-Raphson + * formula applied to those functions gives + * + * r_{i+1} = r_i - f(r_i) / f'(r_i) + * = r_i - (d - R/r_i) r_i^2 / R + * = r_i (2 R - d r_i) / R + * + * Now let e_i be the error in a given iteration, in the sense + * that + * + * d r_i = R + e_i + * i.e. e_i/R = (r_i - r_true) / r_true + * + * so e_i is the _relative_ error in r_i. + * + * We must also introduce a rounding-error term, because the + * division by R always gives an integer. This might make the + * output off by up to 1 (in the negative direction, because + * right-shifting gives floor of the true quotient). So when we + * divide by R, we must imagine adding some f in [0,1). Then we + * have + * + * d r_{i+1} = d r_i (2 R - d r_i) / R - d f + * = (R + e_i) (R - e_i) / R - d f + * = (R^2 - e_i^2) / R - d f + * = R - (e_i^2 / R + d f) + * => e_{i+1} = - (e_i^2 / R + d f) + * + * The sum of two positive quantities is bounded above by twice + * their max, and max |f| = 1, so we can bound this as follows: + * + * |e_{i+1}| <= 2 max (e_i^2/R, d) + * |e_{i+1}/R| <= 2 max ((e_i/R)^2, d/R) + * log2 |R/e_{i+1}| <= min (2 log2 |R/e_i|, log2 |R/d|) - 1 + * + * which tells us that the number of 'good' bits - i.e. + * log2(R/e_i) - very nearly doubles at every iteration (apart + * from that subtraction of 1), until it gets to the same size as + * log2(R/d). In other words, the size of R in bits has to be the + * size of denominator we're putting in, _plus_ the amount of + * precision we want to get back out. + * + * So when we multiply n (the input numerator) by our final + * reciprocal approximation r, but actually r differs from R/d by + * up to 2, then it follows that + * + * n/d - nr/R = n/d - [ n (R/d + e) ] / R + * = n/d - [ (n/d) R + n e ] / R + * = -ne/R + * => 0 <= n/d - nr/R < 2n/R + * + * so our computed quotient can differ from the true n/d by up to + * 2n/R. Hence, as long as we also choose R large enough that 2n/R + * is bounded above by a constant, we can guarantee a bounded + * number of final conditional-subtraction steps. + */ + + /* + * Get at least 32 of the most significant bits of the input + * number. + */ + size_t hiword_index = 0; + uint64_t hibits = 0, lobits = 0; + mp_find_highest_nonzero_word_pair(d, 64 - BIGNUM_INT_BITS, + &hiword_index, &hibits, &lobits); + + /* + * Make a shifted combination of those two words which puts the + * topmost bit of the number at bit 63. + */ + size_t shift_up = 0; + for (size_t i = BIGNUM_INT_BITS_BITS; i-- > 0;) { + size_t sl = 1 << i; /* left shift count */ + size_t sr = 64 - sl; /* complementary right-shift count */ + + /* Should we shift up? */ + unsigned indicator = 1 ^ normalise_to_1_u64(hibits >> sr); + + /* If we do, what will we get? */ + uint64_t new_hibits = (hibits << sl) | (lobits >> sr); + uint64_t new_lobits = lobits << sl; + size_t new_shift_up = shift_up + sl; + + /* Conditionally swap those values in. */ + hibits ^= (hibits ^ new_hibits ) & -(uint64_t)indicator; + lobits ^= (lobits ^ new_lobits ) & -(uint64_t)indicator; + shift_up ^= (shift_up ^ new_shift_up ) & -(size_t) indicator; + } + + /* + * So now we know the most significant 32 bits of d are at the top + * of hibits. Approximate the reciprocal of those bits. + */ + lobits = (uint64_t)recip_approx_32(hibits >> 32) << 32; + hibits = 0; + + /* + * And shift that up by as many bits as the input was shifted up + * just now, so that the product of this approximation and the + * actual input will be close to a fixed power of two regardless + * of where the MSB was. + * + * I do this in another log n individual passes, partly in case + * the CPU's register-controlled shift operation isn't + * time-constant, and also in case the compiler code-generates + * uint64_t shifts out of a variable number of smaller-word shift + * instructions, e.g. by splitting up into cases. + */ + for (size_t i = BIGNUM_INT_BITS_BITS; i-- > 0;) { + size_t sl = 1 << i; /* left shift count */ + size_t sr = 64 - sl; /* complementary right-shift count */ + + /* Should we shift up? */ + unsigned indicator = 1 & (shift_up >> i); + + /* If we do, what will we get? */ + uint64_t new_hibits = (hibits << sl) | (lobits >> sr); + uint64_t new_lobits = lobits << sl; + + /* Conditionally swap those values in. */ + hibits ^= (hibits ^ new_hibits ) & -(uint64_t)indicator; + lobits ^= (lobits ^ new_lobits ) & -(uint64_t)indicator; + } + + /* + * The product of the 128-bit value now in hibits:lobits with the + * 128-bit value we originally retrieved in the same variables + * will be in the vicinity of 2^191. So we'll take log2(R) to be + * 191, plus a multiple of BIGNUM_INT_BITS large enough to allow R + * to hold the combined sizes of n and d. + */ + size_t log2_R; + { + size_t max_log2_n = (n->nw + d->nw) * BIGNUM_INT_BITS; + log2_R = max_log2_n + 3; + log2_R -= size_t_min(191, log2_R); + log2_R = (log2_R + BIGNUM_INT_BITS - 1) & ~(BIGNUM_INT_BITS - 1); + log2_R += 191; + } + + /* Number of words in a bignum capable of holding numbers the size + * of twice R. */ + size_t rw = ((log2_R+2) + BIGNUM_INT_BITS - 1) / BIGNUM_INT_BITS; + + /* + * Now construct our full-sized starting reciprocal approximation. + */ + mp_int *r_approx = mp_make_sized(rw); + size_t output_bit_index; + { + /* Where in the input number did the input 128-bit value come from? */ + size_t input_bit_index = + (hiword_index * BIGNUM_INT_BITS) - (128 - BIGNUM_INT_BITS); + + /* So how far do we need to shift our 64-bit output, if the + * product of those two fixed-size values is 2^191 and we want + * to make it 2^log2_R instead? */ + output_bit_index = log2_R - 191 - input_bit_index; + + /* If we've done all that right, it should be a whole number + * of words. */ + assert(output_bit_index % BIGNUM_INT_BITS == 0); + size_t output_word_index = output_bit_index / BIGNUM_INT_BITS; + + mp_add_integer_into_shifted_by_words( + r_approx, r_approx, lobits, output_word_index); + mp_add_integer_into_shifted_by_words( + r_approx, r_approx, hibits, + output_word_index + 64 / BIGNUM_INT_BITS); + } + + /* + * Make the constant 2*R, which we'll need in the iteration. + */ + mp_int *two_R = mp_make_sized(rw); + mp_add_integer_into_shifted_by_words( + two_R, two_R, (BignumInt)1 << ((log2_R+1) % BIGNUM_INT_BITS), + (log2_R+1) / BIGNUM_INT_BITS); + + /* + * Scratch space. + */ + mp_int *dr = mp_make_sized(rw + d->nw); + mp_int *diff = mp_make_sized(size_t_max(rw, dr->nw)); + mp_int *product = mp_make_sized(rw + diff->nw); + size_t scratchsize = size_t_max( + mp_mul_scratchspace(dr->nw, r_approx->nw, d->nw), + mp_mul_scratchspace(product->nw, r_approx->nw, diff->nw)); + mp_int *scratch = mp_make_sized(scratchsize); + mp_int product_shifted = mp_make_alias( + product, log2_R / BIGNUM_INT_BITS, product->nw); + + /* + * Initial error estimate: the 32-bit output of recip_approx_32 + * differs by less than 2048 (== 2^11) from the true top 32 bits + * of the reciprocal, so the relative error is at most 2^11 + * divided by the 32-bit reciprocal, which at worst is 2^11/2^31 = + * 2^-20. So even in the worst case, we have 20 good bits of + * reciprocal to start with. + */ + size_t good_bits = 31 - 11; + size_t good_bits_needed = BIGNUM_INT_BITS * n->nw + 4; /* add a few */ + + /* + * Now do Newton-Raphson iterations until we have reason to think + * they're not converging any more. + */ + while (good_bits < good_bits_needed) { + /* + * Compute the next iterate. + */ + mp_mul_internal(dr, r_approx, d, *scratch); + mp_sub_into(diff, two_R, dr); + mp_mul_internal(product, r_approx, diff, *scratch); + mp_rshift_fixed_into(r_approx, &product_shifted, + log2_R % BIGNUM_INT_BITS); + + /* + * Adjust the error estimate. + */ + good_bits = good_bits * 2 - 1; + } + + mp_free(dr); + mp_free(diff); + mp_free(product); + mp_free(scratch); + + /* + * Now we've got our reciprocal, we can compute the quotient, by + * multiplying in n and then shifting down by log2_R bits. + */ + mp_int *quotient_full = mp_mul(r_approx, n); + mp_int quotient_alias = mp_make_alias( + quotient_full, log2_R / BIGNUM_INT_BITS, quotient_full->nw); + mp_int *quotient = mp_make_sized(n->nw); + mp_rshift_fixed_into(quotient, "ient_alias, log2_R % BIGNUM_INT_BITS); + + /* + * Next, compute the remainder. + */ + mp_int *remainder = mp_make_sized(d->nw); + mp_mul_into(remainder, quotient, d); + mp_sub_into(remainder, n, remainder); + + /* + * Finally, two conditional subtractions to fix up any remaining + * rounding error. (I _think_ one should be enough, but this + * routine isn't time-critical enough to take chances.) + */ + unsigned q_correction = 0; + for (unsigned iter = 0; iter < 2; iter++) { + unsigned need_correction = mp_cmp_hs(remainder, d); + mp_cond_sub_into(remainder, remainder, d, need_correction); + q_correction += need_correction; + } + mp_add_integer_into(quotient, quotient, q_correction); + + /* + * Now we should have a perfect answer, i.e. 0 <= r < d. + */ + assert(!mp_cmp_hs(remainder, d)); + + if (q_out) + mp_copy_into(q_out, quotient); + if (r_out) + mp_copy_into(r_out, remainder); + + mp_free(r_approx); + mp_free(two_R); + mp_free(quotient_full); + mp_free(quotient); + mp_free(remainder); +} + +mp_int *mp_div(mp_int *n, mp_int *d) +{ + mp_int *q = mp_make_sized(n->nw); + mp_divmod_into(n, d, q, NULL); + return q; +} + +mp_int *mp_mod(mp_int *n, mp_int *d) +{ + mp_int *r = mp_make_sized(d->nw); + mp_divmod_into(n, d, NULL, r); + return r; +} + +mp_int *mp_modmul(mp_int *x, mp_int *y, mp_int *modulus) +{ + mp_int *product = mp_mul(x, y); + mp_int *reduced = mp_mod(product, modulus); + mp_free(product); + return reduced; +} + +mp_int *mp_modadd(mp_int *x, mp_int *y, mp_int *modulus) +{ + mp_int *sum = mp_add(x, y); + mp_int *reduced = mp_mod(sum, modulus); + mp_free(sum); + return reduced; +} + +mp_int *mp_modsub(mp_int *x, mp_int *y, mp_int *modulus) +{ + mp_int *diff = mp_make_sized(size_t_max(x->nw, y->nw)); + mp_sub_into(diff, x, y); + unsigned negate = mp_cmp_hs(y, x); + mp_cond_negate(diff, diff, negate); + mp_int *residue = mp_mod(diff, modulus); + mp_cond_negate(residue, residue, negate); + /* If we've just negated the residue, then it will be < 0 and need + * the modulus adding to it to make it positive - *except* if the + * residue was zero when we negated it. */ + unsigned make_positive = negate & ~mp_eq_integer(residue, 0); + mp_cond_add_into(residue, residue, modulus, make_positive); + mp_free(diff); + return residue; +} + +static mp_int *mp_modadd_in_range(mp_int *x, mp_int *y, mp_int *modulus) +{ + mp_int *sum = mp_make_sized(modulus->nw); + unsigned carry = mp_add_into_internal(sum, x, y); + mp_cond_sub_into(sum, sum, modulus, carry | mp_cmp_hs(sum, modulus)); + return sum; +} + +static mp_int *mp_modsub_in_range(mp_int *x, mp_int *y, mp_int *modulus) +{ + mp_int *diff = mp_make_sized(modulus->nw); + mp_sub_into(diff, x, y); + mp_cond_add_into(diff, diff, modulus, 1 ^ mp_cmp_hs(x, y)); + return diff; +} + +mp_int *monty_add(MontyContext *mc, mp_int *x, mp_int *y) +{ + return mp_modadd_in_range(x, y, mc->m); +} + +mp_int *monty_sub(MontyContext *mc, mp_int *x, mp_int *y) +{ + return mp_modsub_in_range(x, y, mc->m); +} + +void mp_min_into(mp_int *r, mp_int *x, mp_int *y) +{ + mp_select_into(r, x, y, mp_cmp_hs(x, y)); +} + +void mp_max_into(mp_int *r, mp_int *x, mp_int *y) +{ + mp_select_into(r, y, x, mp_cmp_hs(x, y)); +} + +mp_int *mp_min(mp_int *x, mp_int *y) +{ + mp_int *r = mp_make_sized(size_t_min(x->nw, y->nw)); + mp_min_into(r, x, y); + return r; +} + +mp_int *mp_max(mp_int *x, mp_int *y) +{ + mp_int *r = mp_make_sized(size_t_max(x->nw, y->nw)); + mp_max_into(r, x, y); + return r; +} + +mp_int *mp_power_2(size_t power) +{ + mp_int *x = mp_new(power + 1); + mp_set_bit(x, power, 1); + return x; +} + +struct ModsqrtContext { + mp_int *p; /* the prime */ + MontyContext *mc; /* for doing arithmetic mod p */ + + /* Decompose p-1 as 2^e k, for positive integer e and odd k */ + size_t e; + mp_int *k; + mp_int *km1o2; /* (k-1)/2 */ + + /* The user-provided value z which is not a quadratic residue mod + * p, and its kth power. Both in Montgomery form. */ + mp_int *z, *zk; +}; + +ModsqrtContext *modsqrt_new(mp_int *p, mp_int *any_nonsquare_mod_p) +{ + ModsqrtContext *sc = snew(ModsqrtContext); + memset(sc, 0, sizeof(ModsqrtContext)); + + sc->p = mp_copy(p); + sc->mc = monty_new(sc->p); + sc->z = monty_import(sc->mc, any_nonsquare_mod_p); + + /* Find the lowest set bit in p-1. Since this routine expects p to + * be non-secret (typically a well-known standard elliptic curve + * parameter), for once we don't need clever bit tricks. */ + for (sc->e = 1; sc->e < BIGNUM_INT_BITS * p->nw; sc->e++) + if (mp_get_bit(p, sc->e)) + break; + + sc->k = mp_rshift_fixed(p, sc->e); + sc->km1o2 = mp_rshift_fixed(sc->k, 1); + + /* Leave zk to be filled in lazily, since it's more expensive to + * compute. If this context turns out never to be needed, we can + * save the bulk of the setup time this way. */ + + return sc; +} + +static void modsqrt_lazy_setup(ModsqrtContext *sc) +{ + if (!sc->zk) + sc->zk = monty_pow(sc->mc, sc->z, sc->k); +} + +void modsqrt_free(ModsqrtContext *sc) +{ + monty_free(sc->mc); + mp_free(sc->p); + mp_free(sc->z); + mp_free(sc->k); + mp_free(sc->km1o2); + + if (sc->zk) + mp_free(sc->zk); + + sfree(sc); +} + +mp_int *mp_modsqrt(ModsqrtContext *sc, mp_int *x, unsigned *success) +{ + mp_int *mx = monty_import(sc->mc, x); + mp_int *mroot = monty_modsqrt(sc, mx, success); + mp_free(mx); + mp_int *root = monty_export(sc->mc, mroot); + mp_free(mroot); + return root; +} + +/* + * Modular square root, using an algorithm more or less similar to + * Tonelli-Shanks but adapted for constant time. + * + * The basic idea is to write p-1 = k 2^e, where k is odd and e > 0. + * Then the multiplicative group mod p (call it G) has a sequence of + * e+1 nested subgroups G = G_0 > G_1 > G_2 > ... > G_e, where each + * G_i is exactly half the size of G_{i-1} and consists of all the + * squares of elements in G_{i-1}. So the innermost group G_e has + * order k, which is odd, and hence within that group you can take a + * square root by raising to the power (k+1)/2. + * + * Our strategy is to iterate over these groups one by one and make + * sure the number x we're trying to take the square root of is inside + * each one, by adjusting it if it isn't. + * + * Suppose g is a primitive root of p, i.e. a generator of G_0. (We + * don't actually need to know what g _is_; we just imagine it for the + * sake of understanding.) Then G_i consists of precisely the (2^i)th + * powers of g, and hence, you can tell if a number is in G_i if + * raising it to the power k 2^{e-i} gives 1. So the conceptual + * algorithm goes: for each i, test whether x is in G_i by that + * method. If it isn't, then the previous iteration ensured it's in + * G_{i-1}, so it will be an odd power of g^{2^{i-1}}, and hence + * multiplying by any other odd power of g^{2^{i-1}} will give x' in + * G_i. And we have one of those, because our non-square z is an odd + * power of g, so z^{2^{i-1}} is an odd power of g^{2^{i-1}}. + * + * (There's a special case in the very first iteration, where we don't + * have a G_{i-1}. If it turns out that x is not even in G_1, that + * means it's not a square, so we set *success to 0. We still run the + * rest of the algorithm anyway, for the sake of constant time, but we + * don't give a hoot what it returns.) + * + * When we get to the end and have x in G_e, then we can take its + * square root by raising to (k+1)/2. But of course that's not the + * square root of the original input - it's only the square root of + * the adjusted version we produced during the algorithm. To get the + * true output answer we also have to multiply by a power of z, + * namely, z to the power of _half_ whatever we've been multiplying in + * as we go along. (The power of z we multiplied in must have been + * even, because the case in which we would have multiplied in an odd + * power of z is the i=0 case, in which we instead set the failure + * flag.) + * + * The code below is an optimised version of that basic idea, in which + * we _start_ by computing x^k so as to be able to test membership in + * G_i by only a few squarings rather than a full from-scratch modpow + * every time; we also start by computing our candidate output value + * x^{(k+1)/2}. So when the above description says 'adjust x by z^i' + * for some i, we have to adjust our running values of x^k and + * x^{(k+1)/2} by z^{ik} and z^{ik/2} respectively (the latter is safe + * because, as above, i is always even). And it turns out that we + * don't actually have to store the adjusted version of x itself at + * all - we _only_ keep those two powers of it. + */ +mp_int *monty_modsqrt(ModsqrtContext *sc, mp_int *x, unsigned *success) +{ + modsqrt_lazy_setup(sc); + + mp_int *scratch_to_free = mp_make_sized(3 * sc->mc->rw); + mp_int scratch = *scratch_to_free; + + /* + * Compute toret = x^{(k+1)/2}, our starting point for the output + * square root, and also xk = x^k which we'll use as we go along + * for knowing when to apply correction factors. We do this by + * first computing x^{(k-1)/2}, then multiplying it by x, then + * multiplying the two together. + */ + mp_int *toret = monty_pow(sc->mc, x, sc->km1o2); + mp_int xk = mp_alloc_from_scratch(&scratch, sc->mc->rw); + mp_copy_into(&xk, toret); + monty_mul_into(sc->mc, toret, toret, x); + monty_mul_into(sc->mc, &xk, toret, &xk); + + mp_int tmp = mp_alloc_from_scratch(&scratch, sc->mc->rw); + + mp_int power_of_zk = mp_alloc_from_scratch(&scratch, sc->mc->rw); + mp_copy_into(&power_of_zk, sc->zk); + + for (size_t i = 0; i < sc->e; i++) { + mp_copy_into(&tmp, &xk); + for (size_t j = i+1; j < sc->e; j++) + monty_mul_into(sc->mc, &tmp, &tmp, &tmp); + unsigned eq1 = mp_cmp_eq(&tmp, monty_identity(sc->mc)); + + if (i == 0) { + /* One special case: if x=0, then no power of x will ever + * equal 1, but we should still report success on the + * grounds that 0 does have a square root mod p. */ + *success = eq1 | mp_eq_integer(x, 0); + } else { + monty_mul_into(sc->mc, &tmp, toret, &power_of_zk); + mp_select_into(toret, &tmp, toret, eq1); + + monty_mul_into(sc->mc, &power_of_zk, + &power_of_zk, &power_of_zk); + + monty_mul_into(sc->mc, &tmp, &xk, &power_of_zk); + mp_select_into(&xk, &tmp, &xk, eq1); + } + } + + mp_free(scratch_to_free); + + return toret; +} + +mp_int *mp_random_bits_fn(size_t bits, random_read_fn_t random_read) +{ + size_t bytes = (bits + 7) / 8; + uint8_t *randbuf = snewn(bytes, uint8_t); + random_read(randbuf, bytes); + if (bytes) + randbuf[0] &= (2 << ((bits-1) & 7)) - 1; + mp_int *toret = mp_from_bytes_be(make_ptrlen(randbuf, bytes)); + smemclr(randbuf, bytes); + sfree(randbuf); + return toret; +} + +mp_int *mp_random_in_range_fn(mp_int *lo, mp_int *hi, random_read_fn_t rf) +{ + mp_int *n_outcomes = mp_sub(hi, lo); + + /* + * It would be nice to generate our random numbers in such a way + * as to make every possible outcome literally equiprobable. But + * we can't do that in constant time, so we have to go for a very + * close approximation instead. I'm going to take the view that a + * factor of (1+2^-128) between the probabilities of two outcomes + * is acceptable on the grounds that you'd have to examine so many + * outputs to even detect it. + */ + mp_int *unreduced = mp_random_bits_fn(mp_max_bits(n_outcomes) + 128, rf); + mp_int *reduced = mp_mod(unreduced, n_outcomes); + mp_add_into(reduced, reduced, lo); + mp_free(unreduced); + mp_free(n_outcomes); + return reduced; +} diff --git a/0.72_My_PuTTY/mpint.h b/0.73_My_PuTTY/mpint.h similarity index 97% rename from 0.72_My_PuTTY/mpint.h rename to 0.73_My_PuTTY/mpint.h index e15312b..f19362e 100644 --- a/0.72_My_PuTTY/mpint.h +++ b/0.73_My_PuTTY/mpint.h @@ -1,403 +1,403 @@ -#ifndef PUTTY_MPINT_H -#define PUTTY_MPINT_H - -/* - * PuTTY's multiprecision integer library. - * - * This library is written with the aim of avoiding leaking the input - * numbers via timing and cache side channels. This means avoiding - * making any control flow change, or deciding the address of any - * memory access, based on the value of potentially secret input data. - * - * But in a library that has to handle numbers of arbitrary size, you - * can't avoid your control flow depending on the _size_ of the input! - * So the rule is that an mp_int has a nominal size that need not be - * its mathematical size: i.e. if you call (say) mp_from_bytes_be to - * turn an array of 256 bytes into an integer, and all but the last of - * those bytes is zero, then you get an mp_int which has space for 256 - * bytes of data but just happens to store the value 1. So the - * _nominal_ sizes of input data - e.g. the size in bits of some - * public-key modulus - are not considered secret, and control flow is - * allowed to do what it likes based on those sizes. But the same - * function, called with the same _nominally sized_ arguments - * containing different values, should run in the same length of time. - * - * When a function returns an 'mp_int *', it is newly allocated to an - * appropriate nominal size (which, again, depends only on the nominal - * sizes of the inputs). Other functions have 'into' in their name, - * and they instead overwrite the contents of an existing mp_int. - * - * Functions in this API which return values that are logically - * boolean return them as 'unsigned' rather than the C99 bool type. - * That's because C99 bool does an implicit test for non-zero-ness - * when converting any other integer type to it, which compilers might - * well implement using data-dependent control flow. - */ - -/* - * Create and destroy mp_ints. A newly created one is initialised to - * zero. mp_clear also resets an existing number to zero. - */ -mp_int *mp_new(size_t maxbits); -void mp_free(mp_int *); -void mp_clear(mp_int *x); - -/* - * Create mp_ints from various sources: little- and big-endian binary - * data, an ordinary C unsigned integer type, a decimal or hex string - * (given either as a ptrlen or a C NUL-terminated string), and - * another mp_int. - * - * The decimal and hex conversion functions have running time - * dependent on the length of the input data, of course. - */ -mp_int *mp_from_bytes_le(ptrlen bytes); -mp_int *mp_from_bytes_be(ptrlen bytes); -mp_int *mp_from_integer(uintmax_t n); -mp_int *mp_from_decimal_pl(ptrlen decimal); -mp_int *mp_from_decimal(const char *decimal); -mp_int *mp_from_hex_pl(ptrlen hex); -mp_int *mp_from_hex(const char *hex); -mp_int *mp_copy(mp_int *x); - -/* - * A macro for declaring large fixed numbers in source code (such as - * elliptic curve parameters, or standard Diffie-Hellman moduli). The - * idea is that you just write something like - * - * mp_int *value = MP_LITERAL(0x19284376283754638745693467245); - * - * and it newly allocates you an mp_int containing that number. - * - * Internally, the macro argument is stringified and passed to - * mp_from_hex. That's not as fast as it could be if I had instead set - * up some kind of mp_from_array_of_uint64_t() function, but I think - * this system is valuable for the fact that the literal integers - * appear in a very natural syntax that can be pasted directly out - * into, say, Python if you want to cross-check a calculation. - */ -static inline mp_int *mp__from_string_literal(const char *lit) -{ - /* Don't call this directly; it's not equipped to deal with - * hostile data. Use only via the MP_LITERAL macro. */ - if (lit[0] && (lit[1] == 'x' || lit[1] == 'X')) - return mp_from_hex(lit+2); - else - return mp_from_decimal(lit); -} -#define MP_LITERAL(number) mp__from_string_literal(#number) - -/* - * Create an mp_int with the value 2^power. - */ -mp_int *mp_power_2(size_t power); - -/* - * Retrieve the value of a particular bit or byte of an mp_int. The - * byte / bit index is not considered to be secret data. Out-of-range - * byte/bit indices are handled cleanly and return zero. - */ -uint8_t mp_get_byte(mp_int *x, size_t byte); -unsigned mp_get_bit(mp_int *x, size_t bit); - -/* - * Retrieve the value of an mp_int as a uintmax_t, assuming it's small - * enough to fit. - */ -uintmax_t mp_get_integer(mp_int *x); - -/* - * Set an mp_int bit. Again, the bit index is not considered secret. - * Do not pass an out-of-range index, on pain of assertion failure. - */ -void mp_set_bit(mp_int *x, size_t bit, unsigned val); - -/* - * Return the nominal size of an mp_int, in terms of the maximum - * number of bytes or bits that can fit in it. - */ -size_t mp_max_bytes(mp_int *x); -size_t mp_max_bits(mp_int *x); - -/* - * Return the _mathematical_ bit count of an mp_int (not its nominal - * size), i.e. a value n such that 2^{n-1} <= x < 2^n. - * - * This function is supposed to run in constant time for a given - * nominal input size. Of course it's likely that clients of this - * function will promptly need to use the result as the limit of some - * loop (e.g. marshalling an mp_int into an SSH packet, which doesn't - * permit extra prefix zero bytes). But that's up to the caller to - * decide the safety of. - */ -size_t mp_get_nbits(mp_int *x); - -/* - * Return the value of an mp_int as a decimal or hex string. The - * result is dynamically allocated, and the caller is responsible for - * freeing it. - * - * These functions should run in constant time for a given nominal - * input size, even though the exact number of digits returned is - * variable. They always allocate enough space for the largest output - * that might be needed, but they don't always fill it. - */ -char *mp_get_decimal(mp_int *x); -char *mp_get_hex(mp_int *x); -char *mp_get_hex_uppercase(mp_int *x); - -/* - * Compare two mp_ints, or compare one mp_int against a C integer. The - * 'eq' functions return 1 if the two inputs are equal, or 0 - * otherwise; the 'hs' functions return 1 if the first input is >= the - * second, and 0 otherwise. - */ -unsigned mp_cmp_hs(mp_int *a, mp_int *b); -unsigned mp_cmp_eq(mp_int *a, mp_int *b); -unsigned mp_hs_integer(mp_int *x, uintmax_t n); -unsigned mp_eq_integer(mp_int *x, uintmax_t n); - -/* - * Take the minimum or maximum of two mp_ints, without using a - * conditional branch. - */ -void mp_min_into(mp_int *r, mp_int *x, mp_int *y); -void mp_max_into(mp_int *r, mp_int *x, mp_int *y); -mp_int *mp_min(mp_int *x, mp_int *y); -mp_int *mp_max(mp_int *x, mp_int *y); - -/* - * Diagnostic function. Writes out x in hex to the supplied stdio - * stream, preceded by the string 'prefix' and followed by 'suffix'. - * - * This is useful to put temporarily into code, but it's also - * potentially useful to call from a debugger. - */ -void mp_dump(FILE *fp, const char *prefix, mp_int *x, const char *suffix); - -/* - * Overwrite one mp_int with another. - */ -void mp_copy_into(mp_int *dest, mp_int *src); - -/* - * Conditional selection. Overwrites dest with either src0 or src1, - * according to the value of 'choose_src1'. choose_src1 should be 0 or - * 1; if it's 1, then dest is set to src1, otherwise src0. - * - * The value of choose_src1 is considered to be secret data, so - * control flow and memory access should not depend on it. - */ -void mp_select_into(mp_int *dest, mp_int *src0, mp_int *src1, - unsigned choose_src1); - -/* - * Addition, subtraction and multiplication, either targeting an - * existing mp_int or making a new one large enough to hold whatever - * the output might be.. - */ -void mp_add_into(mp_int *r, mp_int *a, mp_int *b); -void mp_sub_into(mp_int *r, mp_int *a, mp_int *b); -void mp_mul_into(mp_int *r, mp_int *a, mp_int *b); -mp_int *mp_add(mp_int *x, mp_int *y); -mp_int *mp_sub(mp_int *x, mp_int *y); -mp_int *mp_mul(mp_int *x, mp_int *y); - -/* - * Bitwise operations. - */ -void mp_and_into(mp_int *r, mp_int *a, mp_int *b); -void mp_or_into(mp_int *r, mp_int *a, mp_int *b); -void mp_xor_into(mp_int *r, mp_int *a, mp_int *b); -void mp_bic_into(mp_int *r, mp_int *a, mp_int *b); - -/* - * Addition, subtraction and multiplication with one argument small - * enough to fit in a C integer. For mp_mul_integer_into, it has to be - * even smaller than that. - */ -void mp_add_integer_into(mp_int *r, mp_int *a, uintmax_t n); -void mp_sub_integer_into(mp_int *r, mp_int *a, uintmax_t n); -void mp_mul_integer_into(mp_int *r, mp_int *a, uint16_t n); - -/* - * Conditional addition/subtraction. If yes == 1, sets r to a+b or a-b - * (respectively). If yes == 0, sets r to just a. 'yes' is considered - * secret data. - */ -void mp_cond_add_into(mp_int *r, mp_int *a, mp_int *b, unsigned yes); -void mp_cond_sub_into(mp_int *r, mp_int *a, mp_int *b, unsigned yes); - -/* - * Swap x0 and x1 if swap == 1, and not if swap == 0. 'swap' is - * considered secret. - */ -void mp_cond_swap(mp_int *x0, mp_int *x1, unsigned swap); - -/* - * Set x to 0 if clear == 1, and otherwise leave it unchanged. 'clear' - * is considered secret. - */ -void mp_cond_clear(mp_int *x, unsigned clear); - -/* - * Division. mp_divmod_into divides n by d, and writes the quotient - * into q and the remainder into r. You can pass either of q and r as - * NULL if you don't need one of the outputs. - * - * mp_div and mp_mod are wrappers that return one or other of those - * outputs as a freshly allocated mp_int of the appropriate size. - * - * Division by zero gives no error, and returns a quotient of 0 and a - * remainder of n (so as to still satisfy the division identity that - * n=qd+r). - */ -void mp_divmod_into(mp_int *n, mp_int *d, mp_int *q, mp_int *r); -mp_int *mp_div(mp_int *n, mp_int *d); -mp_int *mp_mod(mp_int *x, mp_int *modulus); - -/* - * Trivially easy special case of mp_mod: reduce a number mod a power - * of two. - */ -void mp_reduce_mod_2to(mp_int *x, size_t p); - -/* - * Modular inverses. mp_invert computes the inverse of x mod modulus - * (and will expect the two to be coprime). mp_invert_mod_2to computes - * the inverse of x mod 2^p, and is a great deal faster. - */ -mp_int *mp_invert_mod_2to(mp_int *x, size_t p); -mp_int *mp_invert(mp_int *x, mp_int *modulus); - -/* - * System for taking square roots modulo an odd prime. - * - * In order to do this efficiently, you need to provide an extra piece - * of information at setup time, namely a number which is not - * congruent mod p to any square. Given p and that non-square, you can - * use modsqrt_new to make a context containing all the necessary - * equipment for actually calculating the square roots, and then you - * can call mp_modsqrt as many times as you like on that context - * before freeing it. - * - * The output parameter '*success' will be filled in with 1 if the - * operation was successful, or 0 if the input number doesn't have a - * square root mod p at all. In the latter case, the returned mp_int - * will be nonsense and you shouldn't depend on it. - * - * ==== WARNING ==== - * - * This function DOES NOT TREAT THE PRIME MODULUS AS SECRET DATA! It - * will protect the number you're taking the square root _of_, but not - * the number you're taking the root of it _mod_. - * - * (This is because the algorithm requires a number of loop iterations - * equal to the number of factors of 2 in p-1. And the expected use of - * this function is for elliptic-curve point decompression, in which - * the modulus is always a well-known one written down in standards - * documents.) - */ -typedef struct ModsqrtContext ModsqrtContext; -ModsqrtContext *modsqrt_new(mp_int *p, mp_int *any_nonsquare_mod_p); -void modsqrt_free(ModsqrtContext *); -mp_int *mp_modsqrt(ModsqrtContext *sc, mp_int *x, unsigned *success); - -/* - * Functions for Montgomery multiplication, a fast technique for doing - * a long series of modular multiplications all with the same modulus - * (which has to be odd). - * - * You start by calling monty_new to set up a context structure - * containing all the precomputed bits and pieces needed by the - * algorithm. Then, any numbers you want to work with must first be - * transformed into the internal Montgomery representation using - * monty_import; having done that, you can use monty_mul and monty_pow - * to operate on them efficiently; and finally, monty_export will - * convert numbers back out of Montgomery representation to give their - * ordinary values. - * - * Addition and subtraction are not optimised by the Montgomery trick, - * but monty_add and monty_sub are provided anyway for convenience. - * - * There are also monty_invert and monty_modsqrt, which are analogues - * of mp_invert and mp_modsqrt which take their inputs in Montgomery - * representation. For mp_modsqrt, the prime modulus of the - * ModsqrtContext must be the same as the modulus of the MontyContext. - * - * The query functions monty_modulus and monty_identity return numbers - * stored inside the MontyContext, without copying them. The returned - * pointers are still owned by the MontyContext, so don't free them! - */ -MontyContext *monty_new(mp_int *modulus); -void monty_free(MontyContext *mc); -mp_int *monty_modulus(MontyContext *mc); /* doesn't transfer ownership */ -mp_int *monty_identity(MontyContext *mc); /* doesn't transfer ownership */ -void monty_import_into(MontyContext *mc, mp_int *r, mp_int *x); -mp_int *monty_import(MontyContext *mc, mp_int *x); -void monty_export_into(MontyContext *mc, mp_int *r, mp_int *x); -mp_int *monty_export(MontyContext *mc, mp_int *x); -void monty_mul_into(MontyContext *, mp_int *r, mp_int *, mp_int *); -mp_int *monty_add(MontyContext *, mp_int *, mp_int *); -mp_int *monty_sub(MontyContext *, mp_int *, mp_int *); -mp_int *monty_mul(MontyContext *, mp_int *, mp_int *); -mp_int *monty_pow(MontyContext *, mp_int *base, mp_int *exponent); -mp_int *monty_invert(MontyContext *, mp_int *); -mp_int *monty_modsqrt(ModsqrtContext *sc, mp_int *mx, unsigned *success); - -/* - * Modular arithmetic functions which don't use an explicit - * MontyContext. mp_modpow will use one internally (on the assumption - * that the exponent is likely to be large enough to make it - * worthwhile); the other three will just do ordinary non-Montgomery- - * optimised modular reduction. Use mp_modmul if you only have one - * product to compute; if you have a lot, consider using a - * MontyContext in the client code. - */ -mp_int *mp_modpow(mp_int *base, mp_int *exponent, mp_int *modulus); -mp_int *mp_modmul(mp_int *x, mp_int *y, mp_int *modulus); -mp_int *mp_modadd(mp_int *x, mp_int *y, mp_int *modulus); -mp_int *mp_modsub(mp_int *x, mp_int *y, mp_int *modulus); - -/* - * Shift an mp_int right by a given number of bits. The shift count is - * considered to be secret data, and as a result, the algorithm takes - * O(n log n) time instead of the obvious O(n). - */ -mp_int *mp_rshift_safe(mp_int *x, size_t shift); - -/* - * Shift an mp_int left or right by a fixed number of bits. The shift - * count is NOT considered to be secret data! Use this if you're - * always dividing by 2, for example, but don't use it to shift by a - * variable amount derived from another secret number. - * - * The upside is that these functions run in sensible linear time. - */ -void mp_lshift_fixed_into(mp_int *r, mp_int *a, size_t shift); -void mp_rshift_fixed_into(mp_int *r, mp_int *x, size_t shift); -mp_int *mp_rshift_fixed(mp_int *x, size_t shift); - -/* - * Generate a random mp_int. - * - * The _function_ definitions here will expect to be given a gen_data - * function that provides random data. Normally you'd use this using - * random_read() from random.c, and the macro wrappers automate that. - * - * (This is a bit of a dodge to avoid mpint.c having a link-time - * dependency on random.c, so that programs can link against one but - * not the other: if a client of this header uses one of these macros - * then _they_ have link-time dependencies on both modules.) - * - * mp_random_bits[_fn] returns an integer 0 <= n < 2^bits. - * mp_random_in_range[_fn](lo,hi) returns an integer lo <= n < hi. - */ -typedef void (*random_read_fn_t)(void *, size_t); -mp_int *mp_random_bits_fn(size_t bits, random_read_fn_t randfn); -mp_int *mp_random_in_range_fn( - mp_int *lo_inclusive, mp_int *hi_exclusive, random_read_fn_t randfn); -#define mp_random_bits(bits) mp_random_bits_fn(bits, random_read) -#define mp_random_in_range(lo, hi) mp_random_in_range_fn(lo, hi, random_read) - -#endif /* PUTTY_MPINT_H */ +#ifndef PUTTY_MPINT_H +#define PUTTY_MPINT_H + +/* + * PuTTY's multiprecision integer library. + * + * This library is written with the aim of avoiding leaking the input + * numbers via timing and cache side channels. This means avoiding + * making any control flow change, or deciding the address of any + * memory access, based on the value of potentially secret input data. + * + * But in a library that has to handle numbers of arbitrary size, you + * can't avoid your control flow depending on the _size_ of the input! + * So the rule is that an mp_int has a nominal size that need not be + * its mathematical size: i.e. if you call (say) mp_from_bytes_be to + * turn an array of 256 bytes into an integer, and all but the last of + * those bytes is zero, then you get an mp_int which has space for 256 + * bytes of data but just happens to store the value 1. So the + * _nominal_ sizes of input data - e.g. the size in bits of some + * public-key modulus - are not considered secret, and control flow is + * allowed to do what it likes based on those sizes. But the same + * function, called with the same _nominally sized_ arguments + * containing different values, should run in the same length of time. + * + * When a function returns an 'mp_int *', it is newly allocated to an + * appropriate nominal size (which, again, depends only on the nominal + * sizes of the inputs). Other functions have 'into' in their name, + * and they instead overwrite the contents of an existing mp_int. + * + * Functions in this API which return values that are logically + * boolean return them as 'unsigned' rather than the C99 bool type. + * That's because C99 bool does an implicit test for non-zero-ness + * when converting any other integer type to it, which compilers might + * well implement using data-dependent control flow. + */ + +/* + * Create and destroy mp_ints. A newly created one is initialised to + * zero. mp_clear also resets an existing number to zero. + */ +mp_int *mp_new(size_t maxbits); +void mp_free(mp_int *); +void mp_clear(mp_int *x); + +/* + * Create mp_ints from various sources: little- and big-endian binary + * data, an ordinary C unsigned integer type, a decimal or hex string + * (given either as a ptrlen or a C NUL-terminated string), and + * another mp_int. + * + * The decimal and hex conversion functions have running time + * dependent on the length of the input data, of course. + */ +mp_int *mp_from_bytes_le(ptrlen bytes); +mp_int *mp_from_bytes_be(ptrlen bytes); +mp_int *mp_from_integer(uintmax_t n); +mp_int *mp_from_decimal_pl(ptrlen decimal); +mp_int *mp_from_decimal(const char *decimal); +mp_int *mp_from_hex_pl(ptrlen hex); +mp_int *mp_from_hex(const char *hex); +mp_int *mp_copy(mp_int *x); + +/* + * A macro for declaring large fixed numbers in source code (such as + * elliptic curve parameters, or standard Diffie-Hellman moduli). The + * idea is that you just write something like + * + * mp_int *value = MP_LITERAL(0x19284376283754638745693467245); + * + * and it newly allocates you an mp_int containing that number. + * + * Internally, the macro argument is stringified and passed to + * mp_from_hex. That's not as fast as it could be if I had instead set + * up some kind of mp_from_array_of_uint64_t() function, but I think + * this system is valuable for the fact that the literal integers + * appear in a very natural syntax that can be pasted directly out + * into, say, Python if you want to cross-check a calculation. + */ +static inline mp_int *mp__from_string_literal(const char *lit) +{ + /* Don't call this directly; it's not equipped to deal with + * hostile data. Use only via the MP_LITERAL macro. */ + if (lit[0] && (lit[1] == 'x' || lit[1] == 'X')) + return mp_from_hex(lit+2); + else + return mp_from_decimal(lit); +} +#define MP_LITERAL(number) mp__from_string_literal(#number) + +/* + * Create an mp_int with the value 2^power. + */ +mp_int *mp_power_2(size_t power); + +/* + * Retrieve the value of a particular bit or byte of an mp_int. The + * byte / bit index is not considered to be secret data. Out-of-range + * byte/bit indices are handled cleanly and return zero. + */ +uint8_t mp_get_byte(mp_int *x, size_t byte); +unsigned mp_get_bit(mp_int *x, size_t bit); + +/* + * Retrieve the value of an mp_int as a uintmax_t, assuming it's small + * enough to fit. + */ +uintmax_t mp_get_integer(mp_int *x); + +/* + * Set an mp_int bit. Again, the bit index is not considered secret. + * Do not pass an out-of-range index, on pain of assertion failure. + */ +void mp_set_bit(mp_int *x, size_t bit, unsigned val); + +/* + * Return the nominal size of an mp_int, in terms of the maximum + * number of bytes or bits that can fit in it. + */ +size_t mp_max_bytes(mp_int *x); +size_t mp_max_bits(mp_int *x); + +/* + * Return the _mathematical_ bit count of an mp_int (not its nominal + * size), i.e. a value n such that 2^{n-1} <= x < 2^n. + * + * This function is supposed to run in constant time for a given + * nominal input size. Of course it's likely that clients of this + * function will promptly need to use the result as the limit of some + * loop (e.g. marshalling an mp_int into an SSH packet, which doesn't + * permit extra prefix zero bytes). But that's up to the caller to + * decide the safety of. + */ +size_t mp_get_nbits(mp_int *x); + +/* + * Return the value of an mp_int as a decimal or hex string. The + * result is dynamically allocated, and the caller is responsible for + * freeing it. + * + * These functions should run in constant time for a given nominal + * input size, even though the exact number of digits returned is + * variable. They always allocate enough space for the largest output + * that might be needed, but they don't always fill it. + */ +char *mp_get_decimal(mp_int *x); +char *mp_get_hex(mp_int *x); +char *mp_get_hex_uppercase(mp_int *x); + +/* + * Compare two mp_ints, or compare one mp_int against a C integer. The + * 'eq' functions return 1 if the two inputs are equal, or 0 + * otherwise; the 'hs' functions return 1 if the first input is >= the + * second, and 0 otherwise. + */ +unsigned mp_cmp_hs(mp_int *a, mp_int *b); +unsigned mp_cmp_eq(mp_int *a, mp_int *b); +unsigned mp_hs_integer(mp_int *x, uintmax_t n); +unsigned mp_eq_integer(mp_int *x, uintmax_t n); + +/* + * Take the minimum or maximum of two mp_ints, without using a + * conditional branch. + */ +void mp_min_into(mp_int *r, mp_int *x, mp_int *y); +void mp_max_into(mp_int *r, mp_int *x, mp_int *y); +mp_int *mp_min(mp_int *x, mp_int *y); +mp_int *mp_max(mp_int *x, mp_int *y); + +/* + * Diagnostic function. Writes out x in hex to the supplied stdio + * stream, preceded by the string 'prefix' and followed by 'suffix'. + * + * This is useful to put temporarily into code, but it's also + * potentially useful to call from a debugger. + */ +void mp_dump(FILE *fp, const char *prefix, mp_int *x, const char *suffix); + +/* + * Overwrite one mp_int with another. + */ +void mp_copy_into(mp_int *dest, mp_int *src); + +/* + * Conditional selection. Overwrites dest with either src0 or src1, + * according to the value of 'choose_src1'. choose_src1 should be 0 or + * 1; if it's 1, then dest is set to src1, otherwise src0. + * + * The value of choose_src1 is considered to be secret data, so + * control flow and memory access should not depend on it. + */ +void mp_select_into(mp_int *dest, mp_int *src0, mp_int *src1, + unsigned choose_src1); + +/* + * Addition, subtraction and multiplication, either targeting an + * existing mp_int or making a new one large enough to hold whatever + * the output might be.. + */ +void mp_add_into(mp_int *r, mp_int *a, mp_int *b); +void mp_sub_into(mp_int *r, mp_int *a, mp_int *b); +void mp_mul_into(mp_int *r, mp_int *a, mp_int *b); +mp_int *mp_add(mp_int *x, mp_int *y); +mp_int *mp_sub(mp_int *x, mp_int *y); +mp_int *mp_mul(mp_int *x, mp_int *y); + +/* + * Bitwise operations. + */ +void mp_and_into(mp_int *r, mp_int *a, mp_int *b); +void mp_or_into(mp_int *r, mp_int *a, mp_int *b); +void mp_xor_into(mp_int *r, mp_int *a, mp_int *b); +void mp_bic_into(mp_int *r, mp_int *a, mp_int *b); + +/* + * Addition, subtraction and multiplication with one argument small + * enough to fit in a C integer. For mp_mul_integer_into, it has to be + * even smaller than that. + */ +void mp_add_integer_into(mp_int *r, mp_int *a, uintmax_t n); +void mp_sub_integer_into(mp_int *r, mp_int *a, uintmax_t n); +void mp_mul_integer_into(mp_int *r, mp_int *a, uint16_t n); + +/* + * Conditional addition/subtraction. If yes == 1, sets r to a+b or a-b + * (respectively). If yes == 0, sets r to just a. 'yes' is considered + * secret data. + */ +void mp_cond_add_into(mp_int *r, mp_int *a, mp_int *b, unsigned yes); +void mp_cond_sub_into(mp_int *r, mp_int *a, mp_int *b, unsigned yes); + +/* + * Swap x0 and x1 if swap == 1, and not if swap == 0. 'swap' is + * considered secret. + */ +void mp_cond_swap(mp_int *x0, mp_int *x1, unsigned swap); + +/* + * Set x to 0 if clear == 1, and otherwise leave it unchanged. 'clear' + * is considered secret. + */ +void mp_cond_clear(mp_int *x, unsigned clear); + +/* + * Division. mp_divmod_into divides n by d, and writes the quotient + * into q and the remainder into r. You can pass either of q and r as + * NULL if you don't need one of the outputs. + * + * mp_div and mp_mod are wrappers that return one or other of those + * outputs as a freshly allocated mp_int of the appropriate size. + * + * Division by zero gives no error, and returns a quotient of 0 and a + * remainder of n (so as to still satisfy the division identity that + * n=qd+r). + */ +void mp_divmod_into(mp_int *n, mp_int *d, mp_int *q, mp_int *r); +mp_int *mp_div(mp_int *n, mp_int *d); +mp_int *mp_mod(mp_int *x, mp_int *modulus); + +/* + * Trivially easy special case of mp_mod: reduce a number mod a power + * of two. + */ +void mp_reduce_mod_2to(mp_int *x, size_t p); + +/* + * Modular inverses. mp_invert computes the inverse of x mod modulus + * (and will expect the two to be coprime). mp_invert_mod_2to computes + * the inverse of x mod 2^p, and is a great deal faster. + */ +mp_int *mp_invert_mod_2to(mp_int *x, size_t p); +mp_int *mp_invert(mp_int *x, mp_int *modulus); + +/* + * System for taking square roots modulo an odd prime. + * + * In order to do this efficiently, you need to provide an extra piece + * of information at setup time, namely a number which is not + * congruent mod p to any square. Given p and that non-square, you can + * use modsqrt_new to make a context containing all the necessary + * equipment for actually calculating the square roots, and then you + * can call mp_modsqrt as many times as you like on that context + * before freeing it. + * + * The output parameter '*success' will be filled in with 1 if the + * operation was successful, or 0 if the input number doesn't have a + * square root mod p at all. In the latter case, the returned mp_int + * will be nonsense and you shouldn't depend on it. + * + * ==== WARNING ==== + * + * This function DOES NOT TREAT THE PRIME MODULUS AS SECRET DATA! It + * will protect the number you're taking the square root _of_, but not + * the number you're taking the root of it _mod_. + * + * (This is because the algorithm requires a number of loop iterations + * equal to the number of factors of 2 in p-1. And the expected use of + * this function is for elliptic-curve point decompression, in which + * the modulus is always a well-known one written down in standards + * documents.) + */ +typedef struct ModsqrtContext ModsqrtContext; +ModsqrtContext *modsqrt_new(mp_int *p, mp_int *any_nonsquare_mod_p); +void modsqrt_free(ModsqrtContext *); +mp_int *mp_modsqrt(ModsqrtContext *sc, mp_int *x, unsigned *success); + +/* + * Functions for Montgomery multiplication, a fast technique for doing + * a long series of modular multiplications all with the same modulus + * (which has to be odd). + * + * You start by calling monty_new to set up a context structure + * containing all the precomputed bits and pieces needed by the + * algorithm. Then, any numbers you want to work with must first be + * transformed into the internal Montgomery representation using + * monty_import; having done that, you can use monty_mul and monty_pow + * to operate on them efficiently; and finally, monty_export will + * convert numbers back out of Montgomery representation to give their + * ordinary values. + * + * Addition and subtraction are not optimised by the Montgomery trick, + * but monty_add and monty_sub are provided anyway for convenience. + * + * There are also monty_invert and monty_modsqrt, which are analogues + * of mp_invert and mp_modsqrt which take their inputs in Montgomery + * representation. For mp_modsqrt, the prime modulus of the + * ModsqrtContext must be the same as the modulus of the MontyContext. + * + * The query functions monty_modulus and monty_identity return numbers + * stored inside the MontyContext, without copying them. The returned + * pointers are still owned by the MontyContext, so don't free them! + */ +MontyContext *monty_new(mp_int *modulus); +void monty_free(MontyContext *mc); +mp_int *monty_modulus(MontyContext *mc); /* doesn't transfer ownership */ +mp_int *monty_identity(MontyContext *mc); /* doesn't transfer ownership */ +void monty_import_into(MontyContext *mc, mp_int *r, mp_int *x); +mp_int *monty_import(MontyContext *mc, mp_int *x); +void monty_export_into(MontyContext *mc, mp_int *r, mp_int *x); +mp_int *monty_export(MontyContext *mc, mp_int *x); +void monty_mul_into(MontyContext *, mp_int *r, mp_int *, mp_int *); +mp_int *monty_add(MontyContext *, mp_int *, mp_int *); +mp_int *monty_sub(MontyContext *, mp_int *, mp_int *); +mp_int *monty_mul(MontyContext *, mp_int *, mp_int *); +mp_int *monty_pow(MontyContext *, mp_int *base, mp_int *exponent); +mp_int *monty_invert(MontyContext *, mp_int *); +mp_int *monty_modsqrt(ModsqrtContext *sc, mp_int *mx, unsigned *success); + +/* + * Modular arithmetic functions which don't use an explicit + * MontyContext. mp_modpow will use one internally (on the assumption + * that the exponent is likely to be large enough to make it + * worthwhile); the other three will just do ordinary non-Montgomery- + * optimised modular reduction. Use mp_modmul if you only have one + * product to compute; if you have a lot, consider using a + * MontyContext in the client code. + */ +mp_int *mp_modpow(mp_int *base, mp_int *exponent, mp_int *modulus); +mp_int *mp_modmul(mp_int *x, mp_int *y, mp_int *modulus); +mp_int *mp_modadd(mp_int *x, mp_int *y, mp_int *modulus); +mp_int *mp_modsub(mp_int *x, mp_int *y, mp_int *modulus); + +/* + * Shift an mp_int right by a given number of bits. The shift count is + * considered to be secret data, and as a result, the algorithm takes + * O(n log n) time instead of the obvious O(n). + */ +mp_int *mp_rshift_safe(mp_int *x, size_t shift); + +/* + * Shift an mp_int left or right by a fixed number of bits. The shift + * count is NOT considered to be secret data! Use this if you're + * always dividing by 2, for example, but don't use it to shift by a + * variable amount derived from another secret number. + * + * The upside is that these functions run in sensible linear time. + */ +void mp_lshift_fixed_into(mp_int *r, mp_int *a, size_t shift); +void mp_rshift_fixed_into(mp_int *r, mp_int *x, size_t shift); +mp_int *mp_rshift_fixed(mp_int *x, size_t shift); + +/* + * Generate a random mp_int. + * + * The _function_ definitions here will expect to be given a gen_data + * function that provides random data. Normally you'd use this using + * random_read() from random.c, and the macro wrappers automate that. + * + * (This is a bit of a dodge to avoid mpint.c having a link-time + * dependency on random.c, so that programs can link against one but + * not the other: if a client of this header uses one of these macros + * then _they_ have link-time dependencies on both modules.) + * + * mp_random_bits[_fn] returns an integer 0 <= n < 2^bits. + * mp_random_in_range[_fn](lo,hi) returns an integer lo <= n < hi. + */ +typedef void (*random_read_fn_t)(void *, size_t); +mp_int *mp_random_bits_fn(size_t bits, random_read_fn_t randfn); +mp_int *mp_random_in_range_fn( + mp_int *lo_inclusive, mp_int *hi_exclusive, random_read_fn_t randfn); +#define mp_random_bits(bits) mp_random_bits_fn(bits, random_read) +#define mp_random_in_range(lo, hi) mp_random_in_range_fn(lo, hi, random_read) + +#endif /* PUTTY_MPINT_H */ diff --git a/0.72_My_PuTTY/mpint_i.h b/0.73_My_PuTTY/mpint_i.h similarity index 100% rename from 0.72_My_PuTTY/mpint_i.h rename to 0.73_My_PuTTY/mpint_i.h diff --git a/0.72_My_PuTTY/network.h b/0.73_My_PuTTY/network.h similarity index 98% rename from 0.72_My_PuTTY/network.h rename to 0.73_My_PuTTY/network.h index a37d4b9..6910184 100644 --- a/0.72_My_PuTTY/network.h +++ b/0.73_My_PuTTY/network.h @@ -31,7 +31,6 @@ struct SocketVtable { size_t (*write) (Socket *s, const void *data, size_t len); size_t (*write_oob) (Socket *s, const void *data, size_t len); void (*write_eof) (Socket *s); - void (*flush) (Socket *s); void (*set_frozen) (Socket *s, bool is_frozen); /* ignored by tcp, but vital for ssl */ const char *(*socket_error) (Socket *s); @@ -108,8 +107,6 @@ Socket *new_listener(const char *srcaddr, int port, Plug *plug, SockAddr *name_lookup(const char *host, int port, char **canonicalname, Conf *conf, int addressfamily, LogContext *logctx, const char *lookup_reason_for_logging); -bool proxy_for_destination (SockAddr *addr, const char *hostname, int port, - Conf *conf); /* platform-dependent callback from new_connection() */ /* (same caveat about addr as new_connection()) */ @@ -148,7 +145,7 @@ Socket *sk_new(SockAddr *addr, int port, bool privport, bool oobinline, Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, bool local_host_only, int address_family); -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM int sk_getport(Socket *s); #endif @@ -162,8 +159,6 @@ static inline size_t sk_write_oob(Socket *s, const void *data, size_t len) { return s->vt->write_oob(s, data, len); } static inline void sk_write_eof(Socket *s) { s->vt->write_eof(s); } -static inline void sk_flush(Socket *s) -{ s->vt->flush(s); } static inline void plug_log( Plug *p, int type, SockAddr *addr, int port, const char *msg, int code) diff --git a/0.72_My_PuTTY/nocmdline.c b/0.73_My_PuTTY/nocmdline.c similarity index 100% rename from 0.72_My_PuTTY/nocmdline.c rename to 0.73_My_PuTTY/nocmdline.c diff --git a/0.72_My_PuTTY/nocproxy.c b/0.73_My_PuTTY/nocproxy.c similarity index 100% rename from 0.72_My_PuTTY/nocproxy.c rename to 0.73_My_PuTTY/nocproxy.c diff --git a/0.72_My_PuTTY/nogss.c b/0.73_My_PuTTY/nogss.c similarity index 100% rename from 0.72_My_PuTTY/nogss.c rename to 0.73_My_PuTTY/nogss.c diff --git a/0.72_My_PuTTY/noprint.c b/0.73_My_PuTTY/noprint.c similarity index 100% rename from 0.72_My_PuTTY/noprint.c rename to 0.73_My_PuTTY/noprint.c diff --git a/0.72_My_PuTTY/noshare.c b/0.73_My_PuTTY/noshare.c similarity index 100% rename from 0.72_My_PuTTY/noshare.c rename to 0.73_My_PuTTY/noshare.c diff --git a/0.72_My_PuTTY/noterm.c b/0.73_My_PuTTY/noterm.c similarity index 100% rename from 0.72_My_PuTTY/noterm.c rename to 0.73_My_PuTTY/noterm.c diff --git a/0.72_My_PuTTY/notiming.c b/0.73_My_PuTTY/notiming.c similarity index 100% rename from 0.72_My_PuTTY/notiming.c rename to 0.73_My_PuTTY/notiming.c diff --git a/0.72_My_PuTTY/nullplug.c b/0.73_My_PuTTY/nullplug.c similarity index 100% rename from 0.72_My_PuTTY/nullplug.c rename to 0.73_My_PuTTY/nullplug.c diff --git a/0.72_My_PuTTY/pageant.c b/0.73_My_PuTTY/pageant.c similarity index 99% rename from 0.72_My_PuTTY/pageant.c rename to 0.73_My_PuTTY/pageant.c index 2814c32..599de18 100644 --- a/0.72_My_PuTTY/pageant.c +++ b/0.73_My_PuTTY/pageant.c @@ -22,7 +22,7 @@ * won't generate true random numbers. So we must scream, panic, * and exit immediately if that should happen. */ - #ifndef INTEGRATED_AGENT + #ifndef MOD_INTEGRATED_AGENT int random_byte(void) { modalfatalbox("Internal error: attempt to use random numbers in Pageant"); @@ -124,7 +124,7 @@ void pageant_make_keylist1(BinarySink *bs) } } -#ifdef PERSOPORT +#ifdef MOD_PERSO int GetScrumbleKeyFlag(void) ; static int * tab_int = NULL ; void scrumble_int(void) { @@ -310,7 +310,7 @@ void pageant_handle_msg(BinarySink *bs, unsigned response_type; unsigned char response_md5[16]; int i; -#ifdef PERSOPORT +#ifdef MOD_PERSO char *fingerprint; #endif @@ -347,7 +347,7 @@ void pageant_handle_msg(BinarySink *bs, pageant_failure_msg(bs, "key not found", logctx, logfn); goto challenge1_cleanup; } -#ifdef PERSOPORT +#ifdef MOD_PERSO fingerprint = rsa_ssh1_fingerprint(key); if (! confirm_key_usage(fingerprint, key->comment)) { goto challenge1_cleanup; @@ -386,7 +386,7 @@ void pageant_handle_msg(BinarySink *bs, ptrlen keyblob, sigdata; strbuf *signature; uint32_t flags, supported_flags; -#ifdef PERSOPORT +#ifdef MOD_PERSO char* confirm_fingerprint; #endif @@ -424,7 +424,7 @@ void pageant_handle_msg(BinarySink *bs, pageant_failure_msg(bs, "key not found", logctx, logfn); return; } -#ifdef PERSOPORT +#ifdef MOD_PERSO confirm_fingerprint = ssh2_fingerprint_blob(keyblob); if (! confirm_key_usage( confirm_fingerprint , key->comment)) { sfree(confirm_fingerprint); @@ -760,7 +760,7 @@ RSAKey *pageant_nth_ssh1_key(int i) ssh2_userkey *pageant_nth_ssh2_key(int i) { -#ifdef PERSOPORT +#ifdef MOD_PERSO return index234(ssh2keys, get_scrumble_int(i)); #else return index234(ssh2keys, i); @@ -1166,7 +1166,7 @@ int pageant_add_keyfile(Filename *filename, const char *passphrase, * length, so add a placeholder here to fill in * afterwards */ put_uint32(blob, 0); -#ifdef WINCRYPTPORT +#ifdef MOD_WINCRYPT #ifdef USE_CAPI if(0 == strncmp("cert://", filename->path, 7)) { ssh2_userkey_loadpub(filename, NULL, BinarySink_UPCAST(blob), @@ -1186,7 +1186,7 @@ int pageant_add_keyfile(Filename *filename, const char *passphrase, strbuf_free(blob); return PAGEANT_ACTION_FAILURE; } -#ifdef WINCRYPTPORT +#ifdef MOD_WINCRYPT #ifdef USE_CAPI } #endif /* USE_CAPI */ diff --git a/0.72_My_PuTTY/pageant.h b/0.73_My_PuTTY/pageant.h similarity index 99% rename from 0.72_My_PuTTY/pageant.h rename to 0.73_My_PuTTY/pageant.h index 9e7684d..5ccc5cd 100644 --- a/0.72_My_PuTTY/pageant.h +++ b/0.73_My_PuTTY/pageant.h @@ -4,7 +4,7 @@ #include -#ifdef PERSOPORT +#ifdef MOD_PERSO NOTIFYICONDATA trayIcone ; int GetAskConfirmationFlag(void) ; int GetShowBalloonOnKeyUsage( void ) ; diff --git a/0.72_My_PuTTY/pgssapi.c b/0.73_My_PuTTY/pgssapi.c similarity index 100% rename from 0.72_My_PuTTY/pgssapi.c rename to 0.73_My_PuTTY/pgssapi.c diff --git a/0.72_My_PuTTY/pgssapi.h b/0.73_My_PuTTY/pgssapi.h similarity index 100% rename from 0.72_My_PuTTY/pgssapi.h rename to 0.73_My_PuTTY/pgssapi.h diff --git a/0.72_My_PuTTY/pinger.c b/0.73_My_PuTTY/pinger.c similarity index 100% rename from 0.72_My_PuTTY/pinger.c rename to 0.73_My_PuTTY/pinger.c diff --git a/0.72_My_PuTTY/portfwd.c b/0.73_My_PuTTY/portfwd.c similarity index 100% rename from 0.72_My_PuTTY/portfwd.c rename to 0.73_My_PuTTY/portfwd.c diff --git a/0.72_My_PuTTY/pproxy.c b/0.73_My_PuTTY/pproxy.c similarity index 100% rename from 0.72_My_PuTTY/pproxy.c rename to 0.73_My_PuTTY/pproxy.c diff --git a/0.72_My_PuTTY/proxy.c b/0.73_My_PuTTY/proxy.c similarity index 98% rename from 0.72_My_PuTTY/proxy.c rename to 0.73_My_PuTTY/proxy.c index e9ab244..bcecec3 100644 --- a/0.72_My_PuTTY/proxy.c +++ b/0.73_My_PuTTY/proxy.c @@ -57,11 +57,6 @@ void proxy_activate (ProxySocket *p) if (output_after < output_before) plug_sent(p->plug, output_after); - /* if we were asked to flush the output during - * the proxy negotiation process, do so now. - */ - if (p->pending_flush) sk_flush(p->sub_socket); - /* if we have a pending EOF to send, send it */ if (p->pending_eof) sk_write_eof(p->sub_socket); @@ -128,17 +123,6 @@ static void sk_proxy_write_eof (Socket *s) sk_write_eof(ps->sub_socket); } -static void sk_proxy_flush (Socket *s) -{ - ProxySocket *ps = container_of(s, ProxySocket, sock); - - if (ps->state != PROXY_STATE_ACTIVE) { - ps->pending_flush = true; - return; - } - sk_flush(ps->sub_socket); -} - static void sk_proxy_set_frozen (Socket *s, bool is_frozen) { ProxySocket *ps = container_of(s, ProxySocket, sock); @@ -258,7 +242,7 @@ static int plug_proxy_accepting(Plug *p, * This function can accept a NULL pointer as `addr', in which case * it will only check the host name. */ -bool proxy_for_destination (SockAddr *addr, const char *hostname, +static bool proxy_for_destination(SockAddr *addr, const char *hostname, int port, Conf *conf) { int s = 0, e = 0; @@ -393,7 +377,6 @@ static const struct SocketVtable ProxySocket_sockvt = { sk_proxy_write, sk_proxy_write_oob, sk_proxy_write_eof, - sk_proxy_flush, sk_proxy_set_frozen, sk_proxy_socket_error, NULL, /* peer_info */ @@ -437,7 +420,6 @@ Socket *new_connection(SockAddr *addr, const char *hostname, ret->remote_port = port; ret->error = NULL; - ret->pending_flush = false; ret->pending_eof = false; ret->freeze = false; diff --git a/0.72_My_PuTTY/proxy.h b/0.73_My_PuTTY/proxy.h similarity index 99% rename from 0.72_My_PuTTY/proxy.h rename to 0.73_My_PuTTY/proxy.h index 0d5196d..26a76c4 100644 --- a/0.72_My_PuTTY/proxy.h +++ b/0.73_My_PuTTY/proxy.h @@ -25,7 +25,6 @@ struct ProxySocket { bufchain pending_output_data; bufchain pending_oob_output_data; - bool pending_flush; bufchain pending_input_data; bool pending_eof; diff --git a/0.72_My_PuTTY/pscp.c b/0.73_My_PuTTY/pscp.c similarity index 99% rename from 0.72_My_PuTTY/pscp.c rename to 0.73_My_PuTTY/pscp.c index d8ee81a..1a93089 100644 --- a/0.72_My_PuTTY/pscp.c +++ b/0.73_My_PuTTY/pscp.c @@ -50,14 +50,14 @@ static void source(const char *src); static void rsource(const char *src); static void sink(const char *targ, const char *src); -#ifdef PERSOPORT +#ifdef MOD_PERSO void SetAutoStoreSSHKey( void ) ; -#if (defined PERSOPORT) && (!defined FDJ) +#if (defined MOD_PERSO) && (!defined FDJ) char *appname = "PSCP"; #else const char *const appname = "PSCP"; #endif -#ifdef PORTKNOCKINGPORT +#ifdef MOD_PORTKNOCKING int ManagePortKnocking( char* host, char *portstr ) ; #endif #endif @@ -137,14 +137,10 @@ static void tell_user(FILE *stream, const char *fmt, ...) sfree(str2); } -/* - * In pscp, all agent requests should be synchronous, so this is a - * never-called stub. - */ void agent_schedule_callback(void (*callback)(void *, void *, int), void *callback_ctx, void *data, int len) { - assert(!"We shouldn't be here"); + unreachable("all PSCP agent requests should be synchronous"); } /* @@ -468,7 +464,7 @@ static void do_cmd(char *host, char *user, char *cmd) platform_psftp_pre_conn_setup(); -#ifdef PORTKNOCKINGPORT +#ifdef MOD_PORTKNOCKING ManagePortKnocking(conf_get_str(conf,CONF_host),conf_get_str(conf,CONF_portknockingoptions)); #endif @@ -2212,7 +2208,7 @@ static void usage(void) printf(" -sshlog file\n"); printf(" -sshrawlog file\n"); printf(" log protocol details to a file\n"); -#ifdef PERSOPORT +#ifdef MOD_PERSO printf(" -auto-store-sshkey\n"); printf(" store automatically the servers ssh keys\n"); #endif @@ -2311,7 +2307,7 @@ int psftp_main(int argc, char *argv[]) sanitise_stderr = true; } else if (strcmp(argv[i], "-no-sanitise-stderr") == 0) { sanitise_stderr = false; -#ifdef PERSOPORT +#ifdef MOD_PERSO } else if( (strcmp(argv[i], "-auto_store_sshkey")==0) || (strcmp(argv[i], "-auto-store-sshkey") == 0) ) { SetAutoStoreSSHKey(); #endif diff --git a/0.72_My_PuTTY/psftp.c b/0.73_My_PuTTY/psftp.c similarity index 99% rename from 0.72_My_PuTTY/psftp.c rename to 0.73_My_PuTTY/psftp.c index a069a27..5298f8c 100644 --- a/0.72_My_PuTTY/psftp.c +++ b/0.73_My_PuTTY/psftp.c @@ -15,14 +15,14 @@ #include "ssh.h" #include "sftp.h" -#ifdef PERSOPORT +#ifdef MOD_PERSO void SetAutoStoreSSHKey( void ) ; -#if (defined PERSOPORT) && (!defined FDJ) +#if (defined MOD_PERSO) && (!defined FDJ) char *appname = "PSFTP"; #else const char *const appname = "PSFTP"; #endif -#ifdef PORTKNOCKINGPORT +#ifdef MOD_PORTKNOCKING int ManagePortKnocking( char* host, char *portstr ) ; #endif #endif @@ -2437,14 +2437,10 @@ static bool verbose = false; void ldisc_echoedit_update(Ldisc *ldisc) { } -/* - * In psftp, all agent requests should be synchronous, so this is a - * never-called stub. - */ void agent_schedule_callback(void (*callback)(void *, void *, int), void *callback_ctx, void *data, int len) { - assert(!"We shouldn't be here"); + unreachable("all PSFTP agent requests should be synchronous"); } /* @@ -2548,7 +2544,7 @@ static void usage(void) printf(" -sshlog file\n"); printf(" -sshrawlog file\n"); printf(" log protocol details to a file\n"); -#ifdef PERSOPORT +#ifdef MOD_PERSO printf(" -auto-store-sshkey\n"); printf(" store automatically the servers ssh keys\n"); #endif @@ -2868,7 +2864,7 @@ int psftp_main(int argc, char *argv[]) if (!userhost && conf_get_str(conf, CONF_host)[0] != '\0') { userhost = dupstr(conf_get_str(conf, CONF_host)); } -#ifdef PORTKNOCKINGPORT +#ifdef MOD_PORTKNOCKING ManagePortKnocking(conf_get_str(conf,CONF_host),conf_get_str(conf,CONF_portknockingoptions)); #endif diff --git a/0.72_My_PuTTY/psftp.h b/0.73_My_PuTTY/psftp.h similarity index 100% rename from 0.72_My_PuTTY/psftp.h rename to 0.73_My_PuTTY/psftp.h diff --git a/0.72_My_PuTTY/psftpcommon.c b/0.73_My_PuTTY/psftpcommon.c similarity index 100% rename from 0.72_My_PuTTY/psftpcommon.c rename to 0.73_My_PuTTY/psftpcommon.c diff --git a/0.72_My_PuTTY/putty.h b/0.73_My_PuTTY/putty.h similarity index 99% rename from 0.72_My_PuTTY/putty.h rename to 0.73_My_PuTTY/putty.h index d4ab2c7..3b8864a 100644 --- a/0.72_My_PuTTY/putty.h +++ b/0.73_My_PuTTY/putty.h @@ -30,7 +30,7 @@ */ #define MAX_TICK_MINS (INT_MAX / (60 * TICKSPERSEC)) -#ifdef PERSOPORT +#ifdef MOD_PERSO #define ATTR_ITALIC 0x1000000U #include void debug_log( const char *fmt, ...) ; @@ -41,10 +41,10 @@ int switch_private_key_flag( void ) ; BOOL WINAPI SetDefaultDllDirectories( DWORD DirectoryFlags ) ; BOOL WINAPI CryptProtectMemory( LPVOID pData, DWORD cbData, DWORD dwFlags ); #endif -#ifdef PRINTCLIPPORT +#ifdef MOD_PRINTCLIP #define PRINT_TO_CLIPBOARD_STRING "Windows clipboard" #endif -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK /* * HACK: PuttyTray / Nutty * Hyperlink stuff: define @@ -151,7 +151,7 @@ enum { #define ATTR_FGSHIFT 0 #define ATTR_BGSHIFT 9 -#ifdef TUTTYPORT +#ifdef MOD_TUTTY #define ATTR_SELECTED 0x02000000U #endif @@ -412,10 +412,10 @@ enum { enum { /* Protocol back ends. (CONF_protocol) */ PROT_RAW, PROT_TELNET, PROT_RLOGIN, PROT_SSH, -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM PROT_CYGTERM, #endif -#ifdef ADBPORT +#ifdef MOD_ADB PROT_ADB, #endif /* PROT_SERIAL is supported on a subset of platforms, but it doesn't @@ -446,7 +446,7 @@ enum { FUNKY_VT400, FUNKY_VT100P, FUNKY_SCO -#ifdef TUTTYPORT +#ifdef MOD_TUTTY , FUNKY_ATT513, FUNKY_ATT4410, @@ -621,7 +621,7 @@ extern const int be_default_protocol; * Name of this particular application, for use in the config box * and other pieces of text. */ -#if (defined PERSOPORT) && (!defined FDJ) +#if (defined MOD_PERSO) && (!defined FDJ) extern char *appname; #else extern const char *const appname; @@ -1373,7 +1373,8 @@ NORETURN void cleanup_exit(int); X(INT, NONE, serflow) /* SER_FLOW_NONE, SER_FLOW_XONXOFF, ... */ \ /* Keyboard options */ \ X(BOOL, NONE, bksp_is_delete) \ -/* #ifdef PERSOPORT */ \ +/* #ifdef MOD_PERSO */ \ + X(INT, NONE, enter_sends_crlf) \ X(INT, NONE, rxvt_homeend) \ /* #else */ \ /* X(BOOL, NONE, rxvt_homeend) */\ @@ -1537,7 +1538,7 @@ NORETURN void cleanup_exit(int); X(INT, NONE, shadowboldoffset) /* in pixels */ \ X(BOOL, NONE, crhaslf) \ X(STR, NONE, winclass) \ -/* #ifdef PERSOPORT */ \ +/* #ifdef MOD_PERSO */ \ X(INT, NONE, bcdelay) \ X(INT, NONE, initdelay) \ X(INT, NONE, transparencynumber) \ @@ -1567,14 +1568,11 @@ NORETURN void cleanup_exit(int); X(STR, NONE, comment) \ X(INT, NONE, scp_auto_pwd) \ /* #endif */ \ -/* #ifdef ACSPORT */ \ - X(BOOL, NONE, acs_in_utf) \ -/* #endif */ \ -/* #ifdef PRINTCLIPPORT */ \ +/* #ifdef MOD_PRINTCLIP */ \ X(INT, NONE, printclip) \ /* #endif */ \ /* rutty: scripting options */ \ -/* #ifdef RUTTYPORT*/ \ +/* #ifdef MOD_RUTTY*/ \ X(FILENAME, NONE, script_filename) \ X(INT, NONE, script_mode) \ X(INT, NONE, script_line_delay) \ @@ -1588,14 +1586,14 @@ NORETURN void cleanup_exit(int); X(STR, NONE, script_waitfor) \ X(STR, NONE, script_halton) \ /* #endif */ \ -/* #ifdef CYGTERMPORT */ \ +/* #ifdef MOD_CYGTERM */ \ /* Cygterm options */ \ X(INT, NONE, cygautopath) \ X(INT, NONE, cygterm64) \ X(STR, NONE, cygcmd) \ X(INT, NONE, alt_metabit) /* set meta instead of escape */ \ /* #endif */ \ -/* #if (defined IMAGEPORT) && (!defined FDJ) */\ +/* #if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) */\ X(INT, NONE, bg_opacity) \ X(INT, NONE, bg_slideshow) \ X(INT, NONE, bg_type) /* 0=solid 1=wallpaper 2=bitmap */ \ @@ -1605,11 +1603,11 @@ NORETURN void cleanup_exit(int); X(INT, NONE, bg_image_abs_y) \ X(INT, NONE, bg_image_abs_fixed) /* 0=fixed to desktop, 1=fixed to term wnd */ \ /* #endif */ \ -/* #ifdef RECONNECTPORT */ \ +/* #ifdef MOD_RECONNECT */ \ X(INT, NONE, wakeup_reconnect) \ X(INT, NONE, failure_reconnect) \ /* #endif */ \ -/* #ifdef HYPERLINKPORT */ \ +/* #ifdef MOD_HYPERLINK */ \ /* \ * HACK: PuttyTray / Nutty \ * Hyperlink stuff: Underline settings \ @@ -1621,7 +1619,7 @@ NORETURN void cleanup_exit(int); X(FILENAME, NONE, url_browser) \ X(STR, NONE, url_regex) \ /* #endif */ \ -/* #ifdef TUTTYPORT */ \ +/* #ifdef MOD_TUTTY */ \ X(INT, NONE, window_closable) \ X(INT, NONE, window_minimizable) \ X(INT, NONE, window_maximizable) \ @@ -1631,7 +1629,7 @@ NORETURN void cleanup_exit(int); X(INT, NONE, under_colour) \ X(INT, NONE, sel_colour) \ /* #endif */ \ -/* #ifdef ZMODEMPORT */ \ +/* #ifdef MOD_ZMODEM */ \ /* Z modem options */ \ X(FILENAME, NONE, rzcommand) \ X(STR, NONE, rzoptions) \ @@ -1639,11 +1637,11 @@ NORETURN void cleanup_exit(int); X(STR, NONE, szoptions) \ X(STR, NONE, zdownloaddir) \ /* #endif */ \ -/* #ifdef PORTKNOCKINGPORT */ \ +/* #ifdef MOD_PORTKNOCKING */ \ /* port knocking options */ \ X(STR, NONE, portknockingoptions) \ /* #endif */ \ -/* #ifdef DISABLEALTGRPORT */ \ +/* #ifdef MOD_DISABLEALTGR */ \ /* Disable AltGr button */ \ X(INT, NONE, disablealtgr) \ /* #endif */ \ @@ -1654,7 +1652,7 @@ NORETURN void cleanup_exit(int); enum config_primary_key { CONFIG_OPTIONS(CONF_ENUM_DEF) N_CONFIG_OPTIONS }; #undef CONF_ENUM_DEF -#ifdef PERSOPORT +#ifdef MOD_PERSO #define NCFGCOLOURS 34 #else #define NCFGCOLOURS 22 /* number of colours in CONF_colours above */ @@ -1816,7 +1814,7 @@ typedef enum SmallKeypadKey { SKK_HOME, SKK_END, SKK_INSERT, SKK_DELETE, SKK_PGUP, SKK_PGDN, } SmallKeypadKey; -#ifdef KEYMAPPINGPORT +#ifdef MOD_KEYMAPPING int format_arrow_key(char *buf, Terminal *term, int xkey, int modifier, bool alt); #else int format_arrow_key(char *buf, Terminal *term, int xkey, bool ctrl); @@ -1927,7 +1925,7 @@ extern const struct BackendVtable loop_backend; extern const struct BackendVtable raw_backend; -#ifdef ADBPORT +#ifdef MOD_ADB /* * Exports from adb.c. */ @@ -1935,7 +1933,7 @@ extern const struct BackendVtable raw_backend; //extern Backend adb_backend; extern const struct BackendVtable adb_backend ; #endif -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM /* * Exports from cygterm.c. */ diff --git a/0.72_My_PuTTY/puttymem.h b/0.73_My_PuTTY/puttymem.h similarity index 100% rename from 0.72_My_PuTTY/puttymem.h rename to 0.73_My_PuTTY/puttymem.h diff --git a/0.72_My_PuTTY/puttyps.h b/0.73_My_PuTTY/puttyps.h similarity index 100% rename from 0.72_My_PuTTY/puttyps.h rename to 0.73_My_PuTTY/puttyps.h diff --git a/0.72_My_PuTTY/raw.c b/0.73_My_PuTTY/raw.c similarity index 100% rename from 0.72_My_PuTTY/raw.c rename to 0.73_My_PuTTY/raw.c diff --git a/0.72_My_PuTTY/resource.h b/0.73_My_PuTTY/resource.h similarity index 100% rename from 0.72_My_PuTTY/resource.h rename to 0.73_My_PuTTY/resource.h diff --git a/0.72_My_PuTTY/rlogin.c b/0.73_My_PuTTY/rlogin.c similarity index 100% rename from 0.72_My_PuTTY/rlogin.c rename to 0.73_My_PuTTY/rlogin.c diff --git a/0.72_My_PuTTY/scpserver.c b/0.73_My_PuTTY/scpserver.c similarity index 100% rename from 0.72_My_PuTTY/scpserver.c rename to 0.73_My_PuTTY/scpserver.c diff --git a/0.72_My_PuTTY/sercfg.c b/0.73_My_PuTTY/sercfg.c similarity index 100% rename from 0.72_My_PuTTY/sercfg.c rename to 0.73_My_PuTTY/sercfg.c diff --git a/0.72_My_PuTTY/sesschan.c b/0.73_My_PuTTY/sesschan.c similarity index 100% rename from 0.72_My_PuTTY/sesschan.c rename to 0.73_My_PuTTY/sesschan.c diff --git a/0.72_My_PuTTY/sessprep.c b/0.73_My_PuTTY/sessprep.c similarity index 100% rename from 0.72_My_PuTTY/sessprep.c rename to 0.73_My_PuTTY/sessprep.c diff --git a/0.72_My_PuTTY/settings.c b/0.73_My_PuTTY/settings.c similarity index 98% rename from 0.72_My_PuTTY/settings.c rename to 0.73_My_PuTTY/settings.c index d0495d2..24bd588 100644 --- a/0.72_My_PuTTY/settings.c +++ b/0.73_My_PuTTY/settings.c @@ -13,14 +13,14 @@ #endif /* rutty: */ -#ifdef RUTTYPORT +#ifdef MOD_RUTTY #include "script.h" #endif /* rutty */ -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK #include "urlhack.h" #endif -#ifdef PERSOPORT +#ifdef MOD_PERSO extern char PassKey[1024] ; extern int cryptstring( char * st, const char * key ) ; extern int decryptstring( char * st, const char * key ) ; @@ -639,7 +639,8 @@ void save_open_settings(settings_w *sesskey, Conf *conf) write_setting_b(sesskey, "RFCEnviron", conf_get_bool(conf, CONF_rfc_environ)); write_setting_b(sesskey, "PassiveTelnet", conf_get_bool(conf, CONF_passive_telnet)); write_setting_b(sesskey, "BackspaceIsDelete", conf_get_bool(conf, CONF_bksp_is_delete)); -#ifdef PERSOPORT +#ifdef MOD_PERSO + write_setting_i(sesskey, "EnterSendsCrLf", conf_get_int(conf, CONF_enter_sends_crlf)); write_setting_i(sesskey, "RXVTHomeEnd", conf_get_int(conf, CONF_rxvt_homeend)); #else write_setting_b(sesskey, "RXVTHomeEnd", conf_get_bool(conf, CONF_rxvt_homeend)); @@ -715,7 +716,7 @@ void save_open_settings(settings_w *sesskey, Conf *conf) write_setting_b(sesskey, "TrueColour", conf_get_bool(conf, CONF_true_colour)); write_setting_i(sesskey, "BoldAsColour", conf_get_int(conf, CONF_bold_style)-1); -#ifdef TUTTYPORT +#ifdef MOD_TUTTY write_setting_i(sesskey, "WindowClosable", conf_get_int(conf, CONF_window_closable) ); write_setting_i(sesskey, "WindowMinimizable", conf_get_int(conf, CONF_window_minimizable) ); write_setting_i(sesskey, "WindowMaximizable", conf_get_int(conf, CONF_window_maximizable) ); @@ -816,7 +817,7 @@ void save_open_settings(settings_w *sesskey, Conf *conf) write_setting_b(sesskey, "ConnectionSharingDownstream", conf_get_bool(conf, CONF_ssh_connection_sharing_downstream)); wmap(sesskey, "SSHManualHostKeys", conf, CONF_ssh_manual_hostkeys, false); /* rutty: */ -#ifdef RUTTYPORT +#ifdef MOD_RUTTY write_setting_filename(sesskey, "ScriptFileName", conf_get_filename(conf, CONF_script_filename)); write_setting_i(sesskey, "ScriptMode", (conf_get_int(conf, CONF_script_mode)!=SCRIPT_PLAY)?SCRIPT_STOP:conf_get_int(conf, CONF_script_mode)); /* dont save with record on */ write_setting_i(sesskey, "ScriptLineDelay", conf_get_int(conf, CONF_script_line_delay)); @@ -830,11 +831,11 @@ void save_open_settings(settings_w *sesskey, Conf *conf) write_setting_s(sesskey, "ScriptWait", conf_get_str(conf, CONF_script_waitfor)); write_setting_s(sesskey, "ScriptHalt", conf_get_str(conf, CONF_script_halton)); #endif /* rutty */ -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT write_setting_i(sesskey, "WakeupReconnect", conf_get_int(conf,CONF_wakeup_reconnect) ); write_setting_i(sesskey, "FailureReconnect", conf_get_int(conf,CONF_failure_reconnect) ); #endif -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) if( GetBackgroundImageFlag() ) { write_setting_i(sesskey, "BgOpacity", conf_get_int(conf, CONF_bg_opacity) ); write_setting_i(sesskey, "BgSlideshow", conf_get_int(conf, CONF_bg_slideshow) ); @@ -846,7 +847,7 @@ void save_open_settings(settings_w *sesskey, Conf *conf) write_setting_i(sesskey, "BgImagePlacement", conf_get_int(conf, CONF_bg_image_abs_fixed) ); } #endif -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK /* * HACK: PuttyTray / Nutty * Hyperlink stuff: Save hyperlink settings @@ -856,7 +857,7 @@ void save_open_settings(settings_w *sesskey, Conf *conf) write_setting_i(sesskey, "HyperlinkBrowserUseDefault", conf_get_int(conf, CONF_url_defbrowser)); write_setting_filename(sesskey, "HyperlinkBrowser", conf_get_filename(conf, CONF_url_browser)); write_setting_i(sesskey, "HyperlinkRegularExpressionUseDefault", conf_get_int(conf, CONF_url_defregex)); -#ifndef NO_HYPERLINK +#ifndef MOD_NOHYPERLINK if( !strcmp(conf_get_str(conf, CONF_url_regex),"@°@°@NO REGEX--") ) write_setting_s(sesskey, "HyperlinkRegularExpression", urlhack_default_regex ) ; else @@ -865,21 +866,21 @@ void save_open_settings(settings_w *sesskey, Conf *conf) write_setting_s(sesskey, "HyperlinkRegularExpression", conf_get_str(conf, CONF_url_regex)); #endif #endif -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM //if (do_host) write_setting_i(sesskey, "CygtermAltMetabit", conf_get_int(conf, CONF_alt_metabit)); write_setting_i(sesskey, "CygtermAutoPath", conf_get_int(conf, CONF_cygautopath) ); write_setting_i(sesskey, "Cygterm64", conf_get_int(conf, CONF_cygterm64)); write_setting_s(sesskey, "CygtermCommand", conf_get_str(conf, CONF_cygcmd) ); #endif -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM write_setting_filename(sesskey, "rzCommand", conf_get_filename(conf, CONF_rzcommand) ); write_setting_s(sesskey, "rzOptions", conf_get_str(conf, CONF_rzoptions) ); write_setting_filename(sesskey, "szCommand", conf_get_filename(conf, CONF_szcommand) ); write_setting_s(sesskey, "szOptions", conf_get_str(conf, CONF_szoptions) ); write_setting_s(sesskey, "zDownloadDir", conf_get_str(conf, CONF_zdownloaddir) ); #endif -#ifdef PERSOPORT +#ifdef MOD_PERSO if( conf_get_int(conf, CONF_transparencynumber)<-1 ) conf_set_int(conf, CONF_transparencynumber,-1) ; if( conf_get_int(conf, CONF_transparencynumber)>255 ) conf_set_int(conf, CONF_transparencynumber,255) ; write_setting_i(sesskey, "TransparencyValue", conf_get_int(conf, CONF_transparencynumber) ) ; @@ -913,7 +914,7 @@ void save_open_settings(settings_w *sesskey, Conf *conf) strcpy( PassKey, "" ) ; } char pst[4096] ; -#ifndef NO_PASSWORD +#ifndef MOD_NOPASSWORD strcpy( pst, conf_get_str(conf, CONF_password ) ); MASKPASS(pst); cryptstring( pst, PassKey ) ; @@ -924,13 +925,10 @@ void save_open_settings(settings_w *sesskey, Conf *conf) write_setting_s(sesskey, "Comment", conf_get_str(conf, CONF_comment) ); write_setting_i(sesskey, "SCPAutoPwd", conf_get_int(conf, CONF_scp_auto_pwd)); #endif -#ifdef ACSPORT - write_setting_b(sesskey, "ACSinUTF", conf_get_bool(conf, CONF_acs_in_utf)); -#endif -#ifdef PORTKNOCKINGPORT +#ifdef MOD_PORTKNOCKING write_setting_s(sesskey, "PortKnocking", conf_get_str(conf, CONF_portknockingoptions) ); #endif -#ifdef DISABLEALTGRPORT +#ifdef MOD_DISABLEALTGR write_setting_i(sesskey, "DisableAltGr", conf_get_int(conf, CONF_disablealtgr)); #endif } @@ -941,7 +939,7 @@ bool load_settings(const char *section, Conf *conf) sesskey = open_settings_r(section); bool exists = (sesskey != NULL); load_open_settings(sesskey, conf); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( section != NULL ) conf_set_str( conf, CONF_sessionname, section ) ; else conf_set_str( conf, CONF_sessionname, "" ) ; #endif @@ -955,7 +953,7 @@ void load_open_settings(settings_r *sesskey, Conf *conf) { int i; char *prot; -#ifdef PERSOPORT +#ifdef MOD_PERSO /* * HACK: PuTTY-url * Set font quality to cleartype on Windows Vista and above @@ -1188,7 +1186,8 @@ void load_open_settings(settings_r *sesskey, Conf *conf) gppb(sesskey, "RFCEnviron", false, conf, CONF_rfc_environ); gppb(sesskey, "PassiveTelnet", false, conf, CONF_passive_telnet); gppb(sesskey, "BackspaceIsDelete", true, conf, CONF_bksp_is_delete); -#ifdef PERSOPORT +#ifdef MOD_PERSO + gppi(sesskey, "EnterSendsCrLf", 0, conf, CONF_enter_sends_crlf); gppi(sesskey, "RXVTHomeEnd", 0, conf, CONF_rxvt_homeend); #else gppb(sesskey, "RXVTHomeEnd", false, conf, CONF_rxvt_homeend); @@ -1230,7 +1229,7 @@ void load_open_settings(settings_r *sesskey, Conf *conf) gppb(sesskey, "TelnetRet", true, conf, CONF_telnet_newline); gppi(sesskey, "LocalEcho", AUTO, conf, CONF_localecho); gppi(sesskey, "LocalEdit", AUTO, conf, CONF_localedit); -#if (defined PERSOPORT) && (!defined FDJ) +#if (defined MOD_PERSO) && (!defined FDJ) gpps(sesskey, "Answerback", "KiTTY", conf, CONF_answerback); #else gpps(sesskey, "Answerback", "PuTTY", conf, CONF_answerback); @@ -1269,7 +1268,7 @@ void load_open_settings(settings_r *sesskey, Conf *conf) / 1000 #endif ); -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK gppi(sesskey, "ScrollbackLines", 10000, conf, CONF_savelines); #else gppi(sesskey, "ScrollbackLines", 2000, conf, CONF_savelines); @@ -1285,7 +1284,7 @@ void load_open_settings(settings_r *sesskey, Conf *conf) gppi(sesskey, "TermWidth", 80, conf, CONF_width); gppi(sesskey, "TermHeight", 24, conf, CONF_height); gppfont(sesskey, "Font", conf, CONF_font); -#ifdef PERSOPORT +#ifdef MOD_PERSO /* * HACK: PuTTY-url * Set font quality to cleartype on Windows Vista and higher @@ -1306,7 +1305,7 @@ void load_open_settings(settings_r *sesskey, Conf *conf) gppb(sesskey, "TrueColour", true, conf, CONF_true_colour); i = gppi_raw(sesskey, "BoldAsColour", 1); conf_set_int(conf, CONF_bold_style, i+1); -#ifdef TUTTYPORT +#ifdef MOD_TUTTY gppi(sesskey, "WindowClosable", 1, conf, CONF_window_closable); gppi(sesskey, "WindowMinimizable", 1, conf, CONF_window_minimizable); gppi(sesskey, "WindowMaximizable", 1, conf, CONF_window_maximizable); @@ -1395,7 +1394,7 @@ void load_open_settings(settings_r *sesskey, Conf *conf) gppb(sesskey, "CJKAmbigWide", false, conf, CONF_cjk_ambig_wide); gppb(sesskey, "UTF8Override", true, conf, CONF_utf8_override); gpps(sesskey, "Printer", "", conf, CONF_printer); -#ifdef PRINTCLIPPORT +#ifdef MOD_PRINTCLIP if( !strcmp( conf_get_str(conf,CONF_printer),PRINT_TO_CLIPBOARD_STRING) ) { conf_set_int(conf,CONF_printclip,1) ; } else { conf_set_int(conf,CONF_printclip,0) ; } #endif @@ -1462,7 +1461,7 @@ void load_open_settings(settings_r *sesskey, Conf *conf) conf, CONF_ssh_connection_sharing_downstream); gppmap(sesskey, "SSHManualHostKeys", conf, CONF_ssh_manual_hostkeys); /* rutty: */ -#ifdef RUTTYPORT +#ifdef MOD_RUTTY gppfile(sesskey, "ScriptFileName", conf, CONF_script_filename); gppi(sesskey, "ScriptMode", 0, conf, CONF_script_mode); gppi(sesskey, "ScriptLineDelay", 0, conf, CONF_script_line_delay); @@ -1476,11 +1475,11 @@ void load_open_settings(settings_r *sesskey, Conf *conf) gpps(sesskey, "ScriptWait", "", conf, CONF_script_waitfor); gpps(sesskey, "ScriptHalt", "", conf, CONF_script_halton); #endif /* rutty */ -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT gppi(sesskey, "WakeupReconnect", 0, conf, CONF_wakeup_reconnect ); gppi(sesskey, "FailureReconnect", 0, conf, CONF_failure_reconnect ); #endif -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) gppi(sesskey, "BgOpacity", 50, conf, CONF_bg_opacity ); gppi(sesskey, "BgSlideshow", 0, conf, CONF_bg_slideshow ); gppi(sesskey, "BgType", 0, conf, CONF_bg_type ); @@ -1490,7 +1489,7 @@ void load_open_settings(settings_r *sesskey, Conf *conf) gppi(sesskey, "BgImageAbsoluteY", 0, conf, CONF_bg_image_abs_y ); gppi(sesskey, "BgImagePlacement", 0, conf, CONF_bg_image_abs_fixed ); #endif -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK /* * HACK: PuttyTray / Nutty * Hyperlink stuff: Load hyperlink settings @@ -1501,24 +1500,24 @@ void load_open_settings(settings_r *sesskey, Conf *conf) gppfile(sesskey, "HyperlinkBrowser", conf, CONF_url_browser); gppi(sesskey, "HyperlinkRegularExpressionUseDefault", 1, conf, CONF_url_defregex); -#ifndef NO_HYPERLINK +#ifndef MOD_NOHYPERLINK gpps(sesskey, "HyperlinkRegularExpression", urlhack_default_regex, conf, CONF_url_regex); #endif #endif -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM gppi(sesskey, "CygtermAltMetabit", 0, conf, CONF_alt_metabit); gppi(sesskey, "CygtermAutoPath", 1, conf, CONF_cygautopath ); gppi(sesskey, "Cygterm64", 0, conf, CONF_cygterm64); gpps(sesskey, "CygtermCommand", "", conf, CONF_cygcmd ); #endif -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM gppfile(sesskey, "rzCommand", conf, CONF_rzcommand ); gpps(sesskey, "rzOptions", "-e -v", conf, CONF_rzoptions ); gppfile(sesskey, "szCommand", conf, CONF_szcommand ); gpps(sesskey, "szOptions", "-e -v", conf, CONF_szoptions ); gpps(sesskey, "zDownloadDir", "C:\\", conf, CONF_zdownloaddir ); #endif -#ifdef PERSOPORT +#ifdef MOD_PERSO gppi(sesskey, "TransparencyValue", 0, conf, CONF_transparencynumber ) ; if( conf_get_int( conf, CONF_transparencynumber) < -1 ) conf_set_int( conf,CONF_transparencynumber,-1) ; if( conf_get_int( conf, CONF_transparencynumber) > 255 ) conf_set_int( conf,CONF_transparencynumber,255) ; @@ -1546,7 +1545,7 @@ void load_open_settings(settings_r *sesskey, Conf *conf) gppi(sesskey, "WindowState", 0, conf, CONF_windowstate ); gppb(sesskey, "SaveWindowPos", false, conf, CONF_save_windowpos ); /* BKG */ gppb(sesskey, "ForegroundOnBell", false, conf, CONF_foreground_on_bell ); -#ifndef NO_PASSWORD +#ifndef MOD_NOPASSWORD if( strlen(conf_get_str(conf, CONF_host))>0 ) { if( (strlen(conf_get_str(conf, CONF_host))+strlen(conf_get_str(conf, CONF_termtype))) < 1000 ) { sprintf( PassKey, "%s%sKiTTY", conf_get_str(conf, CONF_host), conf_get_str(conf, CONF_termtype) ) ; @@ -1589,13 +1588,10 @@ void load_open_settings(settings_r *sesskey, Conf *conf) gpps(sesskey, "Comment", "", conf, CONF_comment ); gppi(sesskey, "SCPAutoPwd", 0, conf, CONF_scp_auto_pwd); #endif -#ifdef ACSPORT - gppb(sesskey, "ACSinUTF", false, conf, CONF_acs_in_utf); -#endif -#ifdef PORTKNOCKINGPORT +#ifdef MOD_PORTKNOCKING gpps(sesskey, "PortKnocking", "", conf, CONF_portknockingoptions ); #endif -#ifdef DISABLEALTGRPORT +#ifdef MOD_DISABLEALTGR gppi(sesskey, "DisableAltGr", 0, conf, CONF_disablealtgr); #endif } @@ -1678,7 +1674,7 @@ void get_sesslist(struct sesslist *list, bool allocate) list->sessions = NULL; } } -#ifdef PERSOPORT +#ifdef MOD_PERSO /* Fonction de creation d'une session */ void create_settings( const char * name ) { Conf *cfg = conf_new() ; diff --git a/0.72_My_PuTTY/sftp.c b/0.73_My_PuTTY/sftp.c similarity index 100% rename from 0.72_My_PuTTY/sftp.c rename to 0.73_My_PuTTY/sftp.c diff --git a/0.72_My_PuTTY/sftp.h b/0.73_My_PuTTY/sftp.h similarity index 100% rename from 0.72_My_PuTTY/sftp.h rename to 0.73_My_PuTTY/sftp.h diff --git a/0.72_My_PuTTY/sftpcommon.c b/0.73_My_PuTTY/sftpcommon.c similarity index 100% rename from 0.72_My_PuTTY/sftpcommon.c rename to 0.73_My_PuTTY/sftpcommon.c diff --git a/0.72_My_PuTTY/sftpserver.c b/0.73_My_PuTTY/sftpserver.c similarity index 100% rename from 0.72_My_PuTTY/sftpserver.c rename to 0.73_My_PuTTY/sftpserver.c diff --git a/0.72_My_PuTTY/ssh.c b/0.73_My_PuTTY/ssh.c similarity index 96% rename from 0.72_My_PuTTY/ssh.c rename to 0.73_My_PuTTY/ssh.c index 7356ae9..9751dba 100644 --- a/0.72_My_PuTTY/ssh.c +++ b/0.73_My_PuTTY/ssh.c @@ -887,6 +887,9 @@ static const char *ssh_init(Seat *seat, Backend **backend_handle, ssh->ic_out_raw.fn = ssh_bpp_output_raw_data_callback; ssh->ic_out_raw.ctx = ssh; + ssh->term_width = conf_get_int(ssh->conf, CONF_width); + ssh->term_height = conf_get_int(ssh->conf, CONF_height); + ssh->backend.vt = &ssh_backend; *backend_handle = &ssh->backend; diff --git a/0.72_My_PuTTY/ssh.h b/0.73_My_PuTTY/ssh.h similarity index 99% rename from 0.72_My_PuTTY/ssh.h rename to 0.73_My_PuTTY/ssh.h index 7d6e8fc..b08adf2 100644 --- a/0.72_My_PuTTY/ssh.h +++ b/0.73_My_PuTTY/ssh.h @@ -7,7 +7,7 @@ #include "misc.h" -#ifdef PERSOPORT +#ifdef MOD_PERSO void SetUsernameInConfig( char * username ) ; char * ManagePassPhrase( const char * st ) ; void SetPasswordInConfig( const char * password ) ; diff --git a/0.72_My_PuTTY/ssh1bpp.c b/0.73_My_PuTTY/ssh1bpp.c similarity index 100% rename from 0.72_My_PuTTY/ssh1bpp.c rename to 0.73_My_PuTTY/ssh1bpp.c diff --git a/0.72_My_PuTTY/ssh1censor.c b/0.73_My_PuTTY/ssh1censor.c similarity index 100% rename from 0.72_My_PuTTY/ssh1censor.c rename to 0.73_My_PuTTY/ssh1censor.c diff --git a/0.72_My_PuTTY/ssh1connection-client.c b/0.73_My_PuTTY/ssh1connection-client.c similarity index 100% rename from 0.72_My_PuTTY/ssh1connection-client.c rename to 0.73_My_PuTTY/ssh1connection-client.c diff --git a/0.72_My_PuTTY/ssh1connection-server.c b/0.73_My_PuTTY/ssh1connection-server.c similarity index 100% rename from 0.72_My_PuTTY/ssh1connection-server.c rename to 0.73_My_PuTTY/ssh1connection-server.c diff --git a/0.72_My_PuTTY/ssh1connection.c b/0.73_My_PuTTY/ssh1connection.c similarity index 96% rename from 0.72_My_PuTTY/ssh1connection.c rename to 0.73_My_PuTTY/ssh1connection.c index 4ae877f..b06efe7 100644 --- a/0.72_My_PuTTY/ssh1connection.c +++ b/0.73_My_PuTTY/ssh1connection.c @@ -1,844 +1,844 @@ -/* - * Packet protocol layer for the SSH-1 'connection protocol', i.e. - * everything after authentication finishes. - */ - -#include - -#include "putty.h" -#include "ssh.h" -#include "sshbpp.h" -#include "sshppl.h" -#include "sshchan.h" -#include "sshcr.h" -#include "ssh1connection.h" - -static int ssh1_rportfwd_cmp(void *av, void *bv) -{ - struct ssh_rportfwd *a = (struct ssh_rportfwd *) av; - struct ssh_rportfwd *b = (struct ssh_rportfwd *) bv; - int i; - if ( (i = strcmp(a->dhost, b->dhost)) != 0) - return i < 0 ? -1 : +1; - if (a->dport > b->dport) - return +1; - if (a->dport < b->dport) - return -1; - return 0; -} - -static void ssh1_connection_free(PacketProtocolLayer *); -static void ssh1_connection_process_queue(PacketProtocolLayer *); -static void ssh1_connection_special_cmd(PacketProtocolLayer *ppl, - SessionSpecialCode code, int arg); -static bool ssh1_connection_want_user_input(PacketProtocolLayer *ppl); -static void ssh1_connection_got_user_input(PacketProtocolLayer *ppl); -static void ssh1_connection_reconfigure(PacketProtocolLayer *ppl, Conf *conf); - -static const struct PacketProtocolLayerVtable ssh1_connection_vtable = { - ssh1_connection_free, - ssh1_connection_process_queue, - ssh1_common_get_specials, - ssh1_connection_special_cmd, - ssh1_connection_want_user_input, - ssh1_connection_got_user_input, - ssh1_connection_reconfigure, - NULL /* no layer names in SSH-1 */, -}; - -static void ssh1_rportfwd_remove( - ConnectionLayer *cl, struct ssh_rportfwd *rpf); -static SshChannel *ssh1_lportfwd_open( - ConnectionLayer *cl, const char *hostname, int port, - const char *description, const SocketPeerInfo *pi, Channel *chan); -static struct X11FakeAuth *ssh1_add_x11_display( - ConnectionLayer *cl, int authtype, struct X11Display *disp); -static bool ssh1_agent_forwarding_permitted(ConnectionLayer *cl); -static void ssh1_terminal_size(ConnectionLayer *cl, int width, int height); -static void ssh1_stdout_unthrottle(ConnectionLayer *cl, size_t bufsize); -static size_t ssh1_stdin_backlog(ConnectionLayer *cl); -static void ssh1_throttle_all_channels(ConnectionLayer *cl, bool throttled); -static bool ssh1_ldisc_option(ConnectionLayer *cl, int option); -static void ssh1_set_ldisc_option(ConnectionLayer *cl, int option, bool value); -static void ssh1_enable_x_fwd(ConnectionLayer *cl); -static void ssh1_enable_agent_fwd(ConnectionLayer *cl); -static void ssh1_set_wants_user_input(ConnectionLayer *cl, bool wanted); - -static const struct ConnectionLayerVtable ssh1_connlayer_vtable = { - ssh1_rportfwd_alloc, - ssh1_rportfwd_remove, - ssh1_lportfwd_open, - ssh1_session_open, - ssh1_serverside_x11_open, - ssh1_serverside_agent_open, - ssh1_add_x11_display, - NULL /* add_sharing_x11_display */, - NULL /* remove_sharing_x11_display */, - NULL /* send_packet_from_downstream */, - NULL /* alloc_sharing_channel */, - NULL /* delete_sharing_channel */, - NULL /* sharing_queue_global_request */, - NULL /* sharing_no_more_downstreams */, - ssh1_agent_forwarding_permitted, - ssh1_terminal_size, - ssh1_stdout_unthrottle, - ssh1_stdin_backlog, - ssh1_throttle_all_channels, - ssh1_ldisc_option, - ssh1_set_ldisc_option, - ssh1_enable_x_fwd, - ssh1_enable_agent_fwd, - ssh1_set_wants_user_input, -}; - -static size_t ssh1channel_write( - SshChannel *c, bool is_stderr, const void *buf, size_t len); -static void ssh1channel_write_eof(SshChannel *c); -static void ssh1channel_initiate_close(SshChannel *c, const char *err); -static void ssh1channel_unthrottle(SshChannel *c, size_t bufsize); -static Conf *ssh1channel_get_conf(SshChannel *c); -static void ssh1channel_window_override_removed(SshChannel *c) { /* ignore */ } - -static const struct SshChannelVtable ssh1channel_vtable = { - ssh1channel_write, - ssh1channel_write_eof, - ssh1channel_initiate_close, - ssh1channel_unthrottle, - ssh1channel_get_conf, - ssh1channel_window_override_removed, - NULL /* x11_sharing_handover is only used by SSH-2 connection sharing */, - NULL /* send_exit_status */, - NULL /* send_exit_signal */, - NULL /* send_exit_signal_numeric */, - NULL /* request_x11_forwarding */, - NULL /* request_agent_forwarding */, - NULL /* request_pty */, - NULL /* send_env_var */, - NULL /* start_shell */, - NULL /* start_command */, - NULL /* start_subsystem */, - NULL /* send_serial_break */, - NULL /* send_signal */, - NULL /* send_terminal_size_change */, - NULL /* hint_channel_is_simple */, -}; - -static void ssh1_channel_try_eof(struct ssh1_channel *c); -static void ssh1_channel_close_local(struct ssh1_channel *c, - const char *reason); -static void ssh1_channel_destroy(struct ssh1_channel *c); -static void ssh1_channel_check_close(struct ssh1_channel *c); - -static int ssh1_channelcmp(void *av, void *bv) -{ - const struct ssh1_channel *a = (const struct ssh1_channel *) av; - const struct ssh1_channel *b = (const struct ssh1_channel *) bv; - if (a->localid < b->localid) - return -1; - if (a->localid > b->localid) - return +1; - return 0; -} - -static int ssh1_channelfind(void *av, void *bv) -{ - const unsigned *a = (const unsigned *) av; - const struct ssh1_channel *b = (const struct ssh1_channel *) bv; - if (*a < b->localid) - return -1; - if (*a > b->localid) - return +1; - return 0; -} - -void ssh1_channel_free(struct ssh1_channel *c) -{ - if (c->chan) - chan_free(c->chan); - sfree(c); -} - -PacketProtocolLayer *ssh1_connection_new( - Ssh *ssh, Conf *conf, ConnectionLayer **cl_out) -{ - struct ssh1_connection_state *s = snew(struct ssh1_connection_state); - memset(s, 0, sizeof(*s)); - s->ppl.vt = &ssh1_connection_vtable; - - s->conf = conf_copy(conf); - - s->channels = newtree234(ssh1_channelcmp); - - s->x11authtree = newtree234(x11_authcmp); - - /* Need to get the log context for s->cl now, because we won't be - * helpfully notified when a copy is written into s->ppl by our - * owner. */ - s->cl.vt = &ssh1_connlayer_vtable; - s->cl.logctx = ssh_get_logctx(ssh); - - s->portfwdmgr = portfwdmgr_new(&s->cl); - s->rportfwds = newtree234(ssh1_rportfwd_cmp); - - *cl_out = &s->cl; - return &s->ppl; -} - -static void ssh1_connection_free(PacketProtocolLayer *ppl) -{ - struct ssh1_connection_state *s = - container_of(ppl, struct ssh1_connection_state, ppl); - struct X11FakeAuth *auth; - struct ssh1_channel *c; - struct ssh_rportfwd *rpf; - - conf_free(s->conf); - - while ((c = delpos234(s->channels, 0)) != NULL) - ssh1_channel_free(c); - freetree234(s->channels); - if (s->mainchan_chan) - chan_free(s->mainchan_chan); - - if (s->x11disp) - x11_free_display(s->x11disp); - while ((auth = delpos234(s->x11authtree, 0)) != NULL) - x11_free_fake_auth(auth); - freetree234(s->x11authtree); - - while ((rpf = delpos234(s->rportfwds, 0)) != NULL) - free_rportfwd(rpf); - freetree234(s->rportfwds); - portfwdmgr_free(s->portfwdmgr); - - if (s->antispoof_prompt) - free_prompts(s->antispoof_prompt); - - delete_callbacks_for_context(s); - - sfree(s); -} - -void ssh1_connection_set_protoflags(PacketProtocolLayer *ppl, - int local, int remote) -{ - assert(ppl->vt == &ssh1_connection_vtable); - struct ssh1_connection_state *s = - container_of(ppl, struct ssh1_connection_state, ppl); - s->local_protoflags = local; - s->remote_protoflags = remote; -} - -static bool ssh1_connection_filter_queue(struct ssh1_connection_state *s) -{ - PktIn *pktin; - ptrlen data; - struct ssh1_channel *c; - unsigned localid; - bool expect_halfopen; - - while (1) { - if (ssh1_common_filter_queue(&s->ppl)) - return true; - if ((pktin = pq_peek(s->ppl.in_pq)) == NULL) - return false; - - switch (pktin->type) { - case SSH1_MSG_CHANNEL_DATA: - case SSH1_MSG_CHANNEL_OPEN_CONFIRMATION: - case SSH1_MSG_CHANNEL_OPEN_FAILURE: - case SSH1_MSG_CHANNEL_CLOSE: - case SSH1_MSG_CHANNEL_CLOSE_CONFIRMATION: - /* - * Common preliminary code for all the messages from the - * server that cite one of our channel ids: look up that - * channel id, check it exists, and if it's for a sharing - * downstream, pass it on. - */ - localid = get_uint32(pktin); - c = find234(s->channels, &localid, ssh1_channelfind); - - expect_halfopen = ( - pktin->type == SSH1_MSG_CHANNEL_OPEN_CONFIRMATION || - pktin->type == SSH1_MSG_CHANNEL_OPEN_FAILURE); - - if (!c || c->halfopen != expect_halfopen) { - ssh_remote_error( - s->ppl.ssh, "Received %s for %s channel %u", - ssh1_pkt_type(pktin->type), - !c ? "nonexistent" : c->halfopen ? "half-open" : "open", - localid); - return true; - } - - switch (pktin->type) { - case SSH1_MSG_CHANNEL_OPEN_CONFIRMATION: - assert(c->halfopen); - c->remoteid = get_uint32(pktin); - c->halfopen = false; - c->throttling_conn = false; - - chan_open_confirmation(c->chan); - - /* - * Now that the channel is fully open, it's possible - * in principle to immediately close it. Check whether - * it wants us to! - * - * This can occur if a local socket error occurred - * between us sending out CHANNEL_OPEN and receiving - * OPEN_CONFIRMATION. If that happens, all we can do - * is immediately initiate close proceedings now that - * we know the server's id to put in the close - * message. We'll have handled that in this code by - * having already turned c->chan into a zombie, so its - * want_close method (which ssh1_channel_check_close - * will consult) will already be returning true. - */ - ssh1_channel_check_close(c); - - if (c->pending_eof) - ssh1_channel_try_eof(c); /* in case we had a pending EOF */ - break; - - case SSH1_MSG_CHANNEL_OPEN_FAILURE: - assert(c->halfopen); - - chan_open_failed(c->chan, NULL); - chan_free(c->chan); - - del234(s->channels, c); - ssh1_channel_free(c); - break; - - case SSH1_MSG_CHANNEL_DATA: - data = get_string(pktin); - if (!get_err(pktin)) { - int bufsize = chan_send( - c->chan, false, data.ptr, data.len); - - if (!c->throttling_conn && bufsize > SSH1_BUFFER_LIMIT) { - c->throttling_conn = true; - ssh_throttle_conn(s->ppl.ssh, +1); - } - } - break; - - case SSH1_MSG_CHANNEL_CLOSE: - if (!(c->closes & CLOSES_RCVD_CLOSE)) { - c->closes |= CLOSES_RCVD_CLOSE; - chan_send_eof(c->chan); - ssh1_channel_check_close(c); - } - break; - - case SSH1_MSG_CHANNEL_CLOSE_CONFIRMATION: - if (!(c->closes & CLOSES_RCVD_CLOSECONF)) { - if (!(c->closes & CLOSES_SENT_CLOSE)) { - ssh_remote_error( - s->ppl.ssh, - "Received CHANNEL_CLOSE_CONFIRMATION for channel" - " %u for which we never sent CHANNEL_CLOSE\n", - c->localid); - return true; - } - - c->closes |= CLOSES_RCVD_CLOSECONF; - ssh1_channel_check_close(c); - } - break; - } - - pq_pop(s->ppl.in_pq); - break; - - default: - if (ssh1_handle_direction_specific_packet(s, pktin)) { - pq_pop(s->ppl.in_pq); - if (ssh1_check_termination(s)) - return true; - } else { - return false; - } - } - } -} - -static PktIn *ssh1_connection_pop(struct ssh1_connection_state *s) -{ - ssh1_connection_filter_queue(s); - return pq_pop(s->ppl.in_pq); -} - -static void ssh1_connection_process_queue(PacketProtocolLayer *ppl) -{ - struct ssh1_connection_state *s = - container_of(ppl, struct ssh1_connection_state, ppl); - PktIn *pktin; - - if (ssh1_connection_filter_queue(s)) /* no matter why we were called */ - return; - - crBegin(s->crState); - - /* - * Signal the seat that authentication is done, so that it can - * deploy spoofing defences. If it doesn't have any, deploy our - * own fallback one. - * - * We do this here rather than at the end of userauth, because we - * might not have gone through userauth at all (if we're a - * connection-sharing downstream). - */ - if (ssh1_connection_need_antispoof_prompt(s)) { - s->antispoof_prompt = new_prompts(); - s->antispoof_prompt->to_server = true; - s->antispoof_prompt->from_server = false; - s->antispoof_prompt->name = dupstr("Authentication successful"); -#ifndef PERSOPORT - add_prompt( - s->antispoof_prompt, - dupstr("Access granted. Press Return to begin session. "), false); - s->antispoof_ret = seat_get_userpass_input( - s->ppl.seat, s->antispoof_prompt, NULL); -#endif - while (1) { - while (s->antispoof_ret < 0 && - bufchain_size(s->ppl.user_input) > 0) - s->antispoof_ret = seat_get_userpass_input( - s->ppl.seat, s->antispoof_prompt, s->ppl.user_input); - - if (s->antispoof_ret >= 0) - break; - - s->want_user_input = true; - crReturnV; - s->want_user_input = false; - } - free_prompts(s->antispoof_prompt); - s->antispoof_prompt = NULL; - } - - portfwdmgr_config(s->portfwdmgr, s->conf); - s->portfwdmgr_configured = true; - - while (!s->finished_setup) { - ssh1_connection_direction_specific_setup(s); - crReturnV; - } - - while (1) { - - /* - * By this point, most incoming packets are already being - * handled by filter_queue, and we need only pay attention to - * the unusual ones. - */ - - if ((pktin = ssh1_connection_pop(s)) != NULL) { - ssh_proto_error(s->ppl.ssh, "Unexpected packet received, " - "type %d (%s)", pktin->type, - ssh1_pkt_type(pktin->type)); - return; - } - crReturnV; - } - - crFinishV; -} - -static void ssh1_channel_check_close(struct ssh1_channel *c) -{ - struct ssh1_connection_state *s = c->connlayer; - PktOut *pktout; - - if (c->halfopen) { - /* - * If we've sent out our own CHANNEL_OPEN but not yet seen - * either OPEN_CONFIRMATION or OPEN_FAILURE in response, then - * it's too early to be sending close messages of any kind. - */ - return; - } - - if ((!((CLOSES_SENT_CLOSE | CLOSES_RCVD_CLOSE) & ~c->closes) || - chan_want_close(c->chan, (c->closes & CLOSES_SENT_CLOSE), - (c->closes & CLOSES_RCVD_CLOSE))) && - !(c->closes & CLOSES_SENT_CLOSECONF)) { - /* - * We have both sent and received CLOSE (or the channel type - * doesn't need us to), which means the channel is in final - * wind-up. Send CLOSE and/or CLOSE_CONFIRMATION, whichever we - * haven't sent yet. - */ - if (!(c->closes & CLOSES_SENT_CLOSE)) { - pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_MSG_CHANNEL_CLOSE); - put_uint32(pktout, c->remoteid); - pq_push(s->ppl.out_pq, pktout); - c->closes |= CLOSES_SENT_CLOSE; - } - if (c->closes & CLOSES_RCVD_CLOSE) { - pktout = ssh_bpp_new_pktout( - s->ppl.bpp, SSH1_MSG_CHANNEL_CLOSE_CONFIRMATION); - put_uint32(pktout, c->remoteid); - pq_push(s->ppl.out_pq, pktout); - c->closes |= CLOSES_SENT_CLOSECONF; - } - } - - if (!((CLOSES_SENT_CLOSECONF | CLOSES_RCVD_CLOSECONF) & ~c->closes)) { - /* - * We have both sent and received CLOSE_CONFIRMATION, which - * means we're completely done with the channel. - */ - ssh1_channel_destroy(c); - } -} - -static void ssh1_channel_try_eof(struct ssh1_channel *c) -{ - struct ssh1_connection_state *s = c->connlayer; - PktOut *pktout; - assert(c->pending_eof); /* precondition for calling us */ - if (c->halfopen) - return; /* can't close: not even opened yet */ - - c->pending_eof = false; /* we're about to send it */ - - pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_MSG_CHANNEL_CLOSE); - put_uint32(pktout, c->remoteid); - pq_push(s->ppl.out_pq, pktout); - c->closes |= CLOSES_SENT_CLOSE; - - ssh1_channel_check_close(c); -} - -/* - * Close any local socket and free any local resources associated with - * a channel. This converts the channel into a zombie. - */ -static void ssh1_channel_close_local(struct ssh1_channel *c, - const char *reason) -{ - struct ssh1_connection_state *s = c->connlayer; - PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */ - const char *msg = chan_log_close_msg(c->chan); - - if (msg != NULL) - ppl_logevent("%s%s%s", msg, reason ? " " : "", reason ? reason : ""); - - chan_free(c->chan); - c->chan = zombiechan_new(); -} - -static void ssh1_check_termination_callback(void *vctx) -{ - struct ssh1_connection_state *s = (struct ssh1_connection_state *)vctx; - ssh1_check_termination(s); -} - -static void ssh1_channel_destroy(struct ssh1_channel *c) -{ - struct ssh1_connection_state *s = c->connlayer; - - ssh1_channel_close_local(c, NULL); - del234(s->channels, c); - ssh1_channel_free(c); - - /* - * If that was the last channel left open, we might need to - * terminate. But we'll be a bit cautious, by doing that in a - * toplevel callback, just in case anything on the current call - * stack objects to this entire PPL being freed. - */ - queue_toplevel_callback(ssh1_check_termination_callback, s); -} - -bool ssh1_check_termination(struct ssh1_connection_state *s) -{ - /* - * Decide whether we should terminate the SSH connection now. - * Called after a channel goes away, or when the main session - * returns SSH1_SMSG_EXIT_STATUS; we terminate when none of either - * is left. - */ - if (s->session_terminated && count234(s->channels) == 0) { - PktOut *pktout = ssh_bpp_new_pktout( - s->ppl.bpp, SSH1_CMSG_EXIT_CONFIRMATION); - pq_push(s->ppl.out_pq, pktout); - - ssh_user_close(s->ppl.ssh, "Session finished"); - return true; - } - - return false; -} - -/* - * Set up most of a new ssh1_channel. Leaves chan untouched (since it - * will sometimes have been filled in before calling this). - */ -void ssh1_channel_init(struct ssh1_channel *c) -{ - struct ssh1_connection_state *s = c->connlayer; - c->closes = 0; - c->pending_eof = false; - c->throttling_conn = false; - c->sc.vt = &ssh1channel_vtable; - c->sc.cl = &s->cl; - c->localid = alloc_channel_id(s->channels, struct ssh1_channel); - add234(s->channels, c); -} - -static Conf *ssh1channel_get_conf(SshChannel *sc) -{ - struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc); - struct ssh1_connection_state *s = c->connlayer; - return s->conf; -} - -static void ssh1channel_write_eof(SshChannel *sc) -{ - struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc); - - if (c->closes & CLOSES_SENT_CLOSE) - return; - - c->pending_eof = true; - ssh1_channel_try_eof(c); -} - -static void ssh1channel_initiate_close(SshChannel *sc, const char *err) -{ - struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc); - char *reason; - - reason = err ? dupprintf("due to local error: %s", err) : NULL; - ssh1_channel_close_local(c, reason); - sfree(reason); - c->pending_eof = false; /* this will confuse a zombie channel */ - - ssh1_channel_check_close(c); -} - -static void ssh1channel_unthrottle(SshChannel *sc, size_t bufsize) -{ - struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc); - struct ssh1_connection_state *s = c->connlayer; - - if (c->throttling_conn && bufsize <= SSH1_BUFFER_LIMIT) { - c->throttling_conn = false; - ssh_throttle_conn(s->ppl.ssh, -1); - } -} - -static size_t ssh1channel_write( - SshChannel *sc, bool is_stderr, const void *buf, size_t len) -{ - struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc); - struct ssh1_connection_state *s = c->connlayer; - - assert(!(c->closes & CLOSES_SENT_CLOSE)); - - PktOut *pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_MSG_CHANNEL_DATA); - put_uint32(pktout, c->remoteid); - put_string(pktout, buf, len); - pq_push(s->ppl.out_pq, pktout); - - /* - * In SSH-1 we can return 0 here - implying that channels are - * never individually throttled - because the only circumstance - * that can cause throttling will be the whole SSH connection - * backing up, in which case _everything_ will be throttled as a - * whole. - */ - return 0; -} - -static struct X11FakeAuth *ssh1_add_x11_display( - ConnectionLayer *cl, int authtype, struct X11Display *disp) -{ - struct ssh1_connection_state *s = - container_of(cl, struct ssh1_connection_state, cl); - struct X11FakeAuth *auth = x11_invent_fake_auth(s->x11authtree, authtype); - auth->disp = disp; - return auth; -} - -static SshChannel *ssh1_lportfwd_open( - ConnectionLayer *cl, const char *hostname, int port, - const char *description, const SocketPeerInfo *pi, Channel *chan) -{ - struct ssh1_connection_state *s = - container_of(cl, struct ssh1_connection_state, cl); - PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */ - struct ssh1_channel *c = snew(struct ssh1_channel); - PktOut *pktout; - - c->connlayer = s; - ssh1_channel_init(c); - c->halfopen = true; - c->chan = chan; - - ppl_logevent("Opening connection to %s:%d for %s", - hostname, port, description); - - pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_MSG_PORT_OPEN); - put_uint32(pktout, c->localid); - put_stringz(pktout, hostname); - put_uint32(pktout, port); - /* originator string would go here, but we didn't specify - * SSH_PROTOFLAG_HOST_IN_FWD_OPEN */ - pq_push(s->ppl.out_pq, pktout); - - return &c->sc; -} - -static void ssh1_rportfwd_remove(ConnectionLayer *cl, struct ssh_rportfwd *rpf) -{ - /* - * We cannot cancel listening ports on the server side in SSH-1! - * There's no message to support it. - */ -} - -static bool ssh1_agent_forwarding_permitted(ConnectionLayer *cl) -{ - struct ssh1_connection_state *s = - container_of(cl, struct ssh1_connection_state, cl); - return conf_get_bool(s->conf, CONF_agentfwd) && agent_exists(); -} - -static void ssh1_connection_special_cmd(PacketProtocolLayer *ppl, - SessionSpecialCode code, int arg) -{ - struct ssh1_connection_state *s = - container_of(ppl, struct ssh1_connection_state, ppl); - PktOut *pktout; - - if (code == SS_PING || code == SS_NOP) { - if (!(s->ppl.remote_bugs & BUG_CHOKES_ON_SSH1_IGNORE)) { - pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_MSG_IGNORE); - put_stringz(pktout, ""); - pq_push(s->ppl.out_pq, pktout); - } - } else if (s->mainchan) { - mainchan_special_cmd(s->mainchan, code, arg); - } -} - -static void ssh1_terminal_size(ConnectionLayer *cl, int width, int height) -{ - struct ssh1_connection_state *s = - container_of(cl, struct ssh1_connection_state, cl); - - s->term_width = width; - s->term_height = height; - if (s->mainchan) - mainchan_terminal_size(s->mainchan, width, height); -} - -static void ssh1_stdout_unthrottle(ConnectionLayer *cl, size_t bufsize) -{ - struct ssh1_connection_state *s = - container_of(cl, struct ssh1_connection_state, cl); - - if (s->stdout_throttling && bufsize < SSH1_BUFFER_LIMIT) { - s->stdout_throttling = false; - ssh_throttle_conn(s->ppl.ssh, -1); - } -} - -static size_t ssh1_stdin_backlog(ConnectionLayer *cl) -{ - return 0; -} - -static void ssh1_throttle_all_channels(ConnectionLayer *cl, bool throttled) -{ - struct ssh1_connection_state *s = - container_of(cl, struct ssh1_connection_state, cl); - struct ssh1_channel *c; - int i; - - for (i = 0; NULL != (c = index234(s->channels, i)); i++) - chan_set_input_wanted(c->chan, !throttled); -} - -static bool ssh1_ldisc_option(ConnectionLayer *cl, int option) -{ - struct ssh1_connection_state *s = - container_of(cl, struct ssh1_connection_state, cl); - - return s->ldisc_opts[option]; -} - -static void ssh1_set_ldisc_option(ConnectionLayer *cl, int option, bool value) -{ - struct ssh1_connection_state *s = - container_of(cl, struct ssh1_connection_state, cl); - - s->ldisc_opts[option] = value; -} - -static void ssh1_enable_x_fwd(ConnectionLayer *cl) -{ - struct ssh1_connection_state *s = - container_of(cl, struct ssh1_connection_state, cl); - - s->X11_fwd_enabled = true; -} - -static void ssh1_enable_agent_fwd(ConnectionLayer *cl) -{ - struct ssh1_connection_state *s = - container_of(cl, struct ssh1_connection_state, cl); - - s->agent_fwd_enabled = true; -} - -static void ssh1_set_wants_user_input(ConnectionLayer *cl, bool wanted) -{ - struct ssh1_connection_state *s = - container_of(cl, struct ssh1_connection_state, cl); - - s->want_user_input = wanted; - s->finished_setup = true; -} - -static bool ssh1_connection_want_user_input(PacketProtocolLayer *ppl) -{ - struct ssh1_connection_state *s = - container_of(ppl, struct ssh1_connection_state, ppl); - - return s->want_user_input; -} - -static void ssh1_connection_got_user_input(PacketProtocolLayer *ppl) -{ - struct ssh1_connection_state *s = - container_of(ppl, struct ssh1_connection_state, ppl); - - while (s->mainchan && bufchain_size(s->ppl.user_input) > 0) { - /* - * Add user input to the main channel's buffer. - */ - ptrlen data = bufchain_prefix(s->ppl.user_input); - if (data.len > 512) - data.len = 512; - sshfwd_write(&s->mainchan_sc, data.ptr, data.len); - bufchain_consume(s->ppl.user_input, data.len); - } -} - -static void ssh1_connection_reconfigure(PacketProtocolLayer *ppl, Conf *conf) -{ - struct ssh1_connection_state *s = - container_of(ppl, struct ssh1_connection_state, ppl); - - conf_free(s->conf); - s->conf = conf_copy(conf); - - if (s->portfwdmgr_configured) - portfwdmgr_config(s->portfwdmgr, s->conf); -} +/* + * Packet protocol layer for the SSH-1 'connection protocol', i.e. + * everything after authentication finishes. + */ + +#include + +#include "putty.h" +#include "ssh.h" +#include "sshbpp.h" +#include "sshppl.h" +#include "sshchan.h" +#include "sshcr.h" +#include "ssh1connection.h" + +static int ssh1_rportfwd_cmp(void *av, void *bv) +{ + struct ssh_rportfwd *a = (struct ssh_rportfwd *) av; + struct ssh_rportfwd *b = (struct ssh_rportfwd *) bv; + int i; + if ( (i = strcmp(a->dhost, b->dhost)) != 0) + return i < 0 ? -1 : +1; + if (a->dport > b->dport) + return +1; + if (a->dport < b->dport) + return -1; + return 0; +} + +static void ssh1_connection_free(PacketProtocolLayer *); +static void ssh1_connection_process_queue(PacketProtocolLayer *); +static void ssh1_connection_special_cmd(PacketProtocolLayer *ppl, + SessionSpecialCode code, int arg); +static bool ssh1_connection_want_user_input(PacketProtocolLayer *ppl); +static void ssh1_connection_got_user_input(PacketProtocolLayer *ppl); +static void ssh1_connection_reconfigure(PacketProtocolLayer *ppl, Conf *conf); + +static const struct PacketProtocolLayerVtable ssh1_connection_vtable = { + ssh1_connection_free, + ssh1_connection_process_queue, + ssh1_common_get_specials, + ssh1_connection_special_cmd, + ssh1_connection_want_user_input, + ssh1_connection_got_user_input, + ssh1_connection_reconfigure, + NULL /* no layer names in SSH-1 */, +}; + +static void ssh1_rportfwd_remove( + ConnectionLayer *cl, struct ssh_rportfwd *rpf); +static SshChannel *ssh1_lportfwd_open( + ConnectionLayer *cl, const char *hostname, int port, + const char *description, const SocketPeerInfo *pi, Channel *chan); +static struct X11FakeAuth *ssh1_add_x11_display( + ConnectionLayer *cl, int authtype, struct X11Display *disp); +static bool ssh1_agent_forwarding_permitted(ConnectionLayer *cl); +static void ssh1_terminal_size(ConnectionLayer *cl, int width, int height); +static void ssh1_stdout_unthrottle(ConnectionLayer *cl, size_t bufsize); +static size_t ssh1_stdin_backlog(ConnectionLayer *cl); +static void ssh1_throttle_all_channels(ConnectionLayer *cl, bool throttled); +static bool ssh1_ldisc_option(ConnectionLayer *cl, int option); +static void ssh1_set_ldisc_option(ConnectionLayer *cl, int option, bool value); +static void ssh1_enable_x_fwd(ConnectionLayer *cl); +static void ssh1_enable_agent_fwd(ConnectionLayer *cl); +static void ssh1_set_wants_user_input(ConnectionLayer *cl, bool wanted); + +static const struct ConnectionLayerVtable ssh1_connlayer_vtable = { + ssh1_rportfwd_alloc, + ssh1_rportfwd_remove, + ssh1_lportfwd_open, + ssh1_session_open, + ssh1_serverside_x11_open, + ssh1_serverside_agent_open, + ssh1_add_x11_display, + NULL /* add_sharing_x11_display */, + NULL /* remove_sharing_x11_display */, + NULL /* send_packet_from_downstream */, + NULL /* alloc_sharing_channel */, + NULL /* delete_sharing_channel */, + NULL /* sharing_queue_global_request */, + NULL /* sharing_no_more_downstreams */, + ssh1_agent_forwarding_permitted, + ssh1_terminal_size, + ssh1_stdout_unthrottle, + ssh1_stdin_backlog, + ssh1_throttle_all_channels, + ssh1_ldisc_option, + ssh1_set_ldisc_option, + ssh1_enable_x_fwd, + ssh1_enable_agent_fwd, + ssh1_set_wants_user_input, +}; + +static size_t ssh1channel_write( + SshChannel *c, bool is_stderr, const void *buf, size_t len); +static void ssh1channel_write_eof(SshChannel *c); +static void ssh1channel_initiate_close(SshChannel *c, const char *err); +static void ssh1channel_unthrottle(SshChannel *c, size_t bufsize); +static Conf *ssh1channel_get_conf(SshChannel *c); +static void ssh1channel_window_override_removed(SshChannel *c) { /* ignore */ } + +static const struct SshChannelVtable ssh1channel_vtable = { + ssh1channel_write, + ssh1channel_write_eof, + ssh1channel_initiate_close, + ssh1channel_unthrottle, + ssh1channel_get_conf, + ssh1channel_window_override_removed, + NULL /* x11_sharing_handover is only used by SSH-2 connection sharing */, + NULL /* send_exit_status */, + NULL /* send_exit_signal */, + NULL /* send_exit_signal_numeric */, + NULL /* request_x11_forwarding */, + NULL /* request_agent_forwarding */, + NULL /* request_pty */, + NULL /* send_env_var */, + NULL /* start_shell */, + NULL /* start_command */, + NULL /* start_subsystem */, + NULL /* send_serial_break */, + NULL /* send_signal */, + NULL /* send_terminal_size_change */, + NULL /* hint_channel_is_simple */, +}; + +static void ssh1_channel_try_eof(struct ssh1_channel *c); +static void ssh1_channel_close_local(struct ssh1_channel *c, + const char *reason); +static void ssh1_channel_destroy(struct ssh1_channel *c); +static void ssh1_channel_check_close(struct ssh1_channel *c); + +static int ssh1_channelcmp(void *av, void *bv) +{ + const struct ssh1_channel *a = (const struct ssh1_channel *) av; + const struct ssh1_channel *b = (const struct ssh1_channel *) bv; + if (a->localid < b->localid) + return -1; + if (a->localid > b->localid) + return +1; + return 0; +} + +static int ssh1_channelfind(void *av, void *bv) +{ + const unsigned *a = (const unsigned *) av; + const struct ssh1_channel *b = (const struct ssh1_channel *) bv; + if (*a < b->localid) + return -1; + if (*a > b->localid) + return +1; + return 0; +} + +void ssh1_channel_free(struct ssh1_channel *c) +{ + if (c->chan) + chan_free(c->chan); + sfree(c); +} + +PacketProtocolLayer *ssh1_connection_new( + Ssh *ssh, Conf *conf, ConnectionLayer **cl_out) +{ + struct ssh1_connection_state *s = snew(struct ssh1_connection_state); + memset(s, 0, sizeof(*s)); + s->ppl.vt = &ssh1_connection_vtable; + + s->conf = conf_copy(conf); + + s->channels = newtree234(ssh1_channelcmp); + + s->x11authtree = newtree234(x11_authcmp); + + /* Need to get the log context for s->cl now, because we won't be + * helpfully notified when a copy is written into s->ppl by our + * owner. */ + s->cl.vt = &ssh1_connlayer_vtable; + s->cl.logctx = ssh_get_logctx(ssh); + + s->portfwdmgr = portfwdmgr_new(&s->cl); + s->rportfwds = newtree234(ssh1_rportfwd_cmp); + + *cl_out = &s->cl; + return &s->ppl; +} + +static void ssh1_connection_free(PacketProtocolLayer *ppl) +{ + struct ssh1_connection_state *s = + container_of(ppl, struct ssh1_connection_state, ppl); + struct X11FakeAuth *auth; + struct ssh1_channel *c; + struct ssh_rportfwd *rpf; + + conf_free(s->conf); + + while ((c = delpos234(s->channels, 0)) != NULL) + ssh1_channel_free(c); + freetree234(s->channels); + if (s->mainchan_chan) + chan_free(s->mainchan_chan); + + if (s->x11disp) + x11_free_display(s->x11disp); + while ((auth = delpos234(s->x11authtree, 0)) != NULL) + x11_free_fake_auth(auth); + freetree234(s->x11authtree); + + while ((rpf = delpos234(s->rportfwds, 0)) != NULL) + free_rportfwd(rpf); + freetree234(s->rportfwds); + portfwdmgr_free(s->portfwdmgr); + + if (s->antispoof_prompt) + free_prompts(s->antispoof_prompt); + + delete_callbacks_for_context(s); + + sfree(s); +} + +void ssh1_connection_set_protoflags(PacketProtocolLayer *ppl, + int local, int remote) +{ + assert(ppl->vt == &ssh1_connection_vtable); + struct ssh1_connection_state *s = + container_of(ppl, struct ssh1_connection_state, ppl); + s->local_protoflags = local; + s->remote_protoflags = remote; +} + +static bool ssh1_connection_filter_queue(struct ssh1_connection_state *s) +{ + PktIn *pktin; + ptrlen data; + struct ssh1_channel *c; + unsigned localid; + bool expect_halfopen; + + while (1) { + if (ssh1_common_filter_queue(&s->ppl)) + return true; + if ((pktin = pq_peek(s->ppl.in_pq)) == NULL) + return false; + + switch (pktin->type) { + case SSH1_MSG_CHANNEL_DATA: + case SSH1_MSG_CHANNEL_OPEN_CONFIRMATION: + case SSH1_MSG_CHANNEL_OPEN_FAILURE: + case SSH1_MSG_CHANNEL_CLOSE: + case SSH1_MSG_CHANNEL_CLOSE_CONFIRMATION: + /* + * Common preliminary code for all the messages from the + * server that cite one of our channel ids: look up that + * channel id, check it exists, and if it's for a sharing + * downstream, pass it on. + */ + localid = get_uint32(pktin); + c = find234(s->channels, &localid, ssh1_channelfind); + + expect_halfopen = ( + pktin->type == SSH1_MSG_CHANNEL_OPEN_CONFIRMATION || + pktin->type == SSH1_MSG_CHANNEL_OPEN_FAILURE); + + if (!c || c->halfopen != expect_halfopen) { + ssh_remote_error( + s->ppl.ssh, "Received %s for %s channel %u", + ssh1_pkt_type(pktin->type), + !c ? "nonexistent" : c->halfopen ? "half-open" : "open", + localid); + return true; + } + + switch (pktin->type) { + case SSH1_MSG_CHANNEL_OPEN_CONFIRMATION: + assert(c->halfopen); + c->remoteid = get_uint32(pktin); + c->halfopen = false; + c->throttling_conn = false; + + chan_open_confirmation(c->chan); + + /* + * Now that the channel is fully open, it's possible + * in principle to immediately close it. Check whether + * it wants us to! + * + * This can occur if a local socket error occurred + * between us sending out CHANNEL_OPEN and receiving + * OPEN_CONFIRMATION. If that happens, all we can do + * is immediately initiate close proceedings now that + * we know the server's id to put in the close + * message. We'll have handled that in this code by + * having already turned c->chan into a zombie, so its + * want_close method (which ssh1_channel_check_close + * will consult) will already be returning true. + */ + ssh1_channel_check_close(c); + + if (c->pending_eof) + ssh1_channel_try_eof(c); /* in case we had a pending EOF */ + break; + + case SSH1_MSG_CHANNEL_OPEN_FAILURE: + assert(c->halfopen); + + chan_open_failed(c->chan, NULL); + chan_free(c->chan); + + del234(s->channels, c); + ssh1_channel_free(c); + break; + + case SSH1_MSG_CHANNEL_DATA: + data = get_string(pktin); + if (!get_err(pktin)) { + int bufsize = chan_send( + c->chan, false, data.ptr, data.len); + + if (!c->throttling_conn && bufsize > SSH1_BUFFER_LIMIT) { + c->throttling_conn = true; + ssh_throttle_conn(s->ppl.ssh, +1); + } + } + break; + + case SSH1_MSG_CHANNEL_CLOSE: + if (!(c->closes & CLOSES_RCVD_CLOSE)) { + c->closes |= CLOSES_RCVD_CLOSE; + chan_send_eof(c->chan); + ssh1_channel_check_close(c); + } + break; + + case SSH1_MSG_CHANNEL_CLOSE_CONFIRMATION: + if (!(c->closes & CLOSES_RCVD_CLOSECONF)) { + if (!(c->closes & CLOSES_SENT_CLOSE)) { + ssh_remote_error( + s->ppl.ssh, + "Received CHANNEL_CLOSE_CONFIRMATION for channel" + " %u for which we never sent CHANNEL_CLOSE\n", + c->localid); + return true; + } + + c->closes |= CLOSES_RCVD_CLOSECONF; + ssh1_channel_check_close(c); + } + break; + } + + pq_pop(s->ppl.in_pq); + break; + + default: + if (ssh1_handle_direction_specific_packet(s, pktin)) { + pq_pop(s->ppl.in_pq); + if (ssh1_check_termination(s)) + return true; + } else { + return false; + } + } + } +} + +static PktIn *ssh1_connection_pop(struct ssh1_connection_state *s) +{ + ssh1_connection_filter_queue(s); + return pq_pop(s->ppl.in_pq); +} + +static void ssh1_connection_process_queue(PacketProtocolLayer *ppl) +{ + struct ssh1_connection_state *s = + container_of(ppl, struct ssh1_connection_state, ppl); + PktIn *pktin; + + if (ssh1_connection_filter_queue(s)) /* no matter why we were called */ + return; + + crBegin(s->crState); + + /* + * Signal the seat that authentication is done, so that it can + * deploy spoofing defences. If it doesn't have any, deploy our + * own fallback one. + * + * We do this here rather than at the end of userauth, because we + * might not have gone through userauth at all (if we're a + * connection-sharing downstream). + */ + if (ssh1_connection_need_antispoof_prompt(s)) { + s->antispoof_prompt = new_prompts(); + s->antispoof_prompt->to_server = true; + s->antispoof_prompt->from_server = false; + s->antispoof_prompt->name = dupstr("Authentication successful"); +#ifndef MOD_PERSO + add_prompt( + s->antispoof_prompt, + dupstr("Access granted. Press Return to begin session. "), false); + s->antispoof_ret = seat_get_userpass_input( + s->ppl.seat, s->antispoof_prompt, NULL); +#endif + while (1) { + while (s->antispoof_ret < 0 && + bufchain_size(s->ppl.user_input) > 0) + s->antispoof_ret = seat_get_userpass_input( + s->ppl.seat, s->antispoof_prompt, s->ppl.user_input); + + if (s->antispoof_ret >= 0) + break; + + s->want_user_input = true; + crReturnV; + s->want_user_input = false; + } + free_prompts(s->antispoof_prompt); + s->antispoof_prompt = NULL; + } + + portfwdmgr_config(s->portfwdmgr, s->conf); + s->portfwdmgr_configured = true; + + while (!s->finished_setup) { + ssh1_connection_direction_specific_setup(s); + crReturnV; + } + + while (1) { + + /* + * By this point, most incoming packets are already being + * handled by filter_queue, and we need only pay attention to + * the unusual ones. + */ + + if ((pktin = ssh1_connection_pop(s)) != NULL) { + ssh_proto_error(s->ppl.ssh, "Unexpected packet received, " + "type %d (%s)", pktin->type, + ssh1_pkt_type(pktin->type)); + return; + } + crReturnV; + } + + crFinishV; +} + +static void ssh1_channel_check_close(struct ssh1_channel *c) +{ + struct ssh1_connection_state *s = c->connlayer; + PktOut *pktout; + + if (c->halfopen) { + /* + * If we've sent out our own CHANNEL_OPEN but not yet seen + * either OPEN_CONFIRMATION or OPEN_FAILURE in response, then + * it's too early to be sending close messages of any kind. + */ + return; + } + + if ((!((CLOSES_SENT_CLOSE | CLOSES_RCVD_CLOSE) & ~c->closes) || + chan_want_close(c->chan, (c->closes & CLOSES_SENT_CLOSE), + (c->closes & CLOSES_RCVD_CLOSE))) && + !(c->closes & CLOSES_SENT_CLOSECONF)) { + /* + * We have both sent and received CLOSE (or the channel type + * doesn't need us to), which means the channel is in final + * wind-up. Send CLOSE and/or CLOSE_CONFIRMATION, whichever we + * haven't sent yet. + */ + if (!(c->closes & CLOSES_SENT_CLOSE)) { + pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_MSG_CHANNEL_CLOSE); + put_uint32(pktout, c->remoteid); + pq_push(s->ppl.out_pq, pktout); + c->closes |= CLOSES_SENT_CLOSE; + } + if (c->closes & CLOSES_RCVD_CLOSE) { + pktout = ssh_bpp_new_pktout( + s->ppl.bpp, SSH1_MSG_CHANNEL_CLOSE_CONFIRMATION); + put_uint32(pktout, c->remoteid); + pq_push(s->ppl.out_pq, pktout); + c->closes |= CLOSES_SENT_CLOSECONF; + } + } + + if (!((CLOSES_SENT_CLOSECONF | CLOSES_RCVD_CLOSECONF) & ~c->closes)) { + /* + * We have both sent and received CLOSE_CONFIRMATION, which + * means we're completely done with the channel. + */ + ssh1_channel_destroy(c); + } +} + +static void ssh1_channel_try_eof(struct ssh1_channel *c) +{ + struct ssh1_connection_state *s = c->connlayer; + PktOut *pktout; + assert(c->pending_eof); /* precondition for calling us */ + if (c->halfopen) + return; /* can't close: not even opened yet */ + + c->pending_eof = false; /* we're about to send it */ + + pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_MSG_CHANNEL_CLOSE); + put_uint32(pktout, c->remoteid); + pq_push(s->ppl.out_pq, pktout); + c->closes |= CLOSES_SENT_CLOSE; + + ssh1_channel_check_close(c); +} + +/* + * Close any local socket and free any local resources associated with + * a channel. This converts the channel into a zombie. + */ +static void ssh1_channel_close_local(struct ssh1_channel *c, + const char *reason) +{ + struct ssh1_connection_state *s = c->connlayer; + PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */ + const char *msg = chan_log_close_msg(c->chan); + + if (msg != NULL) + ppl_logevent("%s%s%s", msg, reason ? " " : "", reason ? reason : ""); + + chan_free(c->chan); + c->chan = zombiechan_new(); +} + +static void ssh1_check_termination_callback(void *vctx) +{ + struct ssh1_connection_state *s = (struct ssh1_connection_state *)vctx; + ssh1_check_termination(s); +} + +static void ssh1_channel_destroy(struct ssh1_channel *c) +{ + struct ssh1_connection_state *s = c->connlayer; + + ssh1_channel_close_local(c, NULL); + del234(s->channels, c); + ssh1_channel_free(c); + + /* + * If that was the last channel left open, we might need to + * terminate. But we'll be a bit cautious, by doing that in a + * toplevel callback, just in case anything on the current call + * stack objects to this entire PPL being freed. + */ + queue_toplevel_callback(ssh1_check_termination_callback, s); +} + +bool ssh1_check_termination(struct ssh1_connection_state *s) +{ + /* + * Decide whether we should terminate the SSH connection now. + * Called after a channel goes away, or when the main session + * returns SSH1_SMSG_EXIT_STATUS; we terminate when none of either + * is left. + */ + if (s->session_terminated && count234(s->channels) == 0) { + PktOut *pktout = ssh_bpp_new_pktout( + s->ppl.bpp, SSH1_CMSG_EXIT_CONFIRMATION); + pq_push(s->ppl.out_pq, pktout); + + ssh_user_close(s->ppl.ssh, "Session finished"); + return true; + } + + return false; +} + +/* + * Set up most of a new ssh1_channel. Leaves chan untouched (since it + * will sometimes have been filled in before calling this). + */ +void ssh1_channel_init(struct ssh1_channel *c) +{ + struct ssh1_connection_state *s = c->connlayer; + c->closes = 0; + c->pending_eof = false; + c->throttling_conn = false; + c->sc.vt = &ssh1channel_vtable; + c->sc.cl = &s->cl; + c->localid = alloc_channel_id(s->channels, struct ssh1_channel); + add234(s->channels, c); +} + +static Conf *ssh1channel_get_conf(SshChannel *sc) +{ + struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc); + struct ssh1_connection_state *s = c->connlayer; + return s->conf; +} + +static void ssh1channel_write_eof(SshChannel *sc) +{ + struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc); + + if (c->closes & CLOSES_SENT_CLOSE) + return; + + c->pending_eof = true; + ssh1_channel_try_eof(c); +} + +static void ssh1channel_initiate_close(SshChannel *sc, const char *err) +{ + struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc); + char *reason; + + reason = err ? dupprintf("due to local error: %s", err) : NULL; + ssh1_channel_close_local(c, reason); + sfree(reason); + c->pending_eof = false; /* this will confuse a zombie channel */ + + ssh1_channel_check_close(c); +} + +static void ssh1channel_unthrottle(SshChannel *sc, size_t bufsize) +{ + struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc); + struct ssh1_connection_state *s = c->connlayer; + + if (c->throttling_conn && bufsize <= SSH1_BUFFER_LIMIT) { + c->throttling_conn = false; + ssh_throttle_conn(s->ppl.ssh, -1); + } +} + +static size_t ssh1channel_write( + SshChannel *sc, bool is_stderr, const void *buf, size_t len) +{ + struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc); + struct ssh1_connection_state *s = c->connlayer; + + assert(!(c->closes & CLOSES_SENT_CLOSE)); + + PktOut *pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_MSG_CHANNEL_DATA); + put_uint32(pktout, c->remoteid); + put_string(pktout, buf, len); + pq_push(s->ppl.out_pq, pktout); + + /* + * In SSH-1 we can return 0 here - implying that channels are + * never individually throttled - because the only circumstance + * that can cause throttling will be the whole SSH connection + * backing up, in which case _everything_ will be throttled as a + * whole. + */ + return 0; +} + +static struct X11FakeAuth *ssh1_add_x11_display( + ConnectionLayer *cl, int authtype, struct X11Display *disp) +{ + struct ssh1_connection_state *s = + container_of(cl, struct ssh1_connection_state, cl); + struct X11FakeAuth *auth = x11_invent_fake_auth(s->x11authtree, authtype); + auth->disp = disp; + return auth; +} + +static SshChannel *ssh1_lportfwd_open( + ConnectionLayer *cl, const char *hostname, int port, + const char *description, const SocketPeerInfo *pi, Channel *chan) +{ + struct ssh1_connection_state *s = + container_of(cl, struct ssh1_connection_state, cl); + PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */ + struct ssh1_channel *c = snew(struct ssh1_channel); + PktOut *pktout; + + c->connlayer = s; + ssh1_channel_init(c); + c->halfopen = true; + c->chan = chan; + + ppl_logevent("Opening connection to %s:%d for %s", + hostname, port, description); + + pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_MSG_PORT_OPEN); + put_uint32(pktout, c->localid); + put_stringz(pktout, hostname); + put_uint32(pktout, port); + /* originator string would go here, but we didn't specify + * SSH_PROTOFLAG_HOST_IN_FWD_OPEN */ + pq_push(s->ppl.out_pq, pktout); + + return &c->sc; +} + +static void ssh1_rportfwd_remove(ConnectionLayer *cl, struct ssh_rportfwd *rpf) +{ + /* + * We cannot cancel listening ports on the server side in SSH-1! + * There's no message to support it. + */ +} + +static bool ssh1_agent_forwarding_permitted(ConnectionLayer *cl) +{ + struct ssh1_connection_state *s = + container_of(cl, struct ssh1_connection_state, cl); + return conf_get_bool(s->conf, CONF_agentfwd) && agent_exists(); +} + +static void ssh1_connection_special_cmd(PacketProtocolLayer *ppl, + SessionSpecialCode code, int arg) +{ + struct ssh1_connection_state *s = + container_of(ppl, struct ssh1_connection_state, ppl); + PktOut *pktout; + + if (code == SS_PING || code == SS_NOP) { + if (!(s->ppl.remote_bugs & BUG_CHOKES_ON_SSH1_IGNORE)) { + pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_MSG_IGNORE); + put_stringz(pktout, ""); + pq_push(s->ppl.out_pq, pktout); + } + } else if (s->mainchan) { + mainchan_special_cmd(s->mainchan, code, arg); + } +} + +static void ssh1_terminal_size(ConnectionLayer *cl, int width, int height) +{ + struct ssh1_connection_state *s = + container_of(cl, struct ssh1_connection_state, cl); + + s->term_width = width; + s->term_height = height; + if (s->mainchan) + mainchan_terminal_size(s->mainchan, width, height); +} + +static void ssh1_stdout_unthrottle(ConnectionLayer *cl, size_t bufsize) +{ + struct ssh1_connection_state *s = + container_of(cl, struct ssh1_connection_state, cl); + + if (s->stdout_throttling && bufsize < SSH1_BUFFER_LIMIT) { + s->stdout_throttling = false; + ssh_throttle_conn(s->ppl.ssh, -1); + } +} + +static size_t ssh1_stdin_backlog(ConnectionLayer *cl) +{ + return 0; +} + +static void ssh1_throttle_all_channels(ConnectionLayer *cl, bool throttled) +{ + struct ssh1_connection_state *s = + container_of(cl, struct ssh1_connection_state, cl); + struct ssh1_channel *c; + int i; + + for (i = 0; NULL != (c = index234(s->channels, i)); i++) + chan_set_input_wanted(c->chan, !throttled); +} + +static bool ssh1_ldisc_option(ConnectionLayer *cl, int option) +{ + struct ssh1_connection_state *s = + container_of(cl, struct ssh1_connection_state, cl); + + return s->ldisc_opts[option]; +} + +static void ssh1_set_ldisc_option(ConnectionLayer *cl, int option, bool value) +{ + struct ssh1_connection_state *s = + container_of(cl, struct ssh1_connection_state, cl); + + s->ldisc_opts[option] = value; +} + +static void ssh1_enable_x_fwd(ConnectionLayer *cl) +{ + struct ssh1_connection_state *s = + container_of(cl, struct ssh1_connection_state, cl); + + s->X11_fwd_enabled = true; +} + +static void ssh1_enable_agent_fwd(ConnectionLayer *cl) +{ + struct ssh1_connection_state *s = + container_of(cl, struct ssh1_connection_state, cl); + + s->agent_fwd_enabled = true; +} + +static void ssh1_set_wants_user_input(ConnectionLayer *cl, bool wanted) +{ + struct ssh1_connection_state *s = + container_of(cl, struct ssh1_connection_state, cl); + + s->want_user_input = wanted; + s->finished_setup = true; +} + +static bool ssh1_connection_want_user_input(PacketProtocolLayer *ppl) +{ + struct ssh1_connection_state *s = + container_of(ppl, struct ssh1_connection_state, ppl); + + return s->want_user_input; +} + +static void ssh1_connection_got_user_input(PacketProtocolLayer *ppl) +{ + struct ssh1_connection_state *s = + container_of(ppl, struct ssh1_connection_state, ppl); + + while (s->mainchan && bufchain_size(s->ppl.user_input) > 0) { + /* + * Add user input to the main channel's buffer. + */ + ptrlen data = bufchain_prefix(s->ppl.user_input); + if (data.len > 512) + data.len = 512; + sshfwd_write(&s->mainchan_sc, data.ptr, data.len); + bufchain_consume(s->ppl.user_input, data.len); + } +} + +static void ssh1_connection_reconfigure(PacketProtocolLayer *ppl, Conf *conf) +{ + struct ssh1_connection_state *s = + container_of(ppl, struct ssh1_connection_state, ppl); + + conf_free(s->conf); + s->conf = conf_copy(conf); + + if (s->portfwdmgr_configured) + portfwdmgr_config(s->portfwdmgr, s->conf); +} diff --git a/0.72_My_PuTTY/ssh1connection.h b/0.73_My_PuTTY/ssh1connection.h similarity index 100% rename from 0.72_My_PuTTY/ssh1connection.h rename to 0.73_My_PuTTY/ssh1connection.h diff --git a/0.72_My_PuTTY/ssh1login-server.c b/0.73_My_PuTTY/ssh1login-server.c similarity index 100% rename from 0.72_My_PuTTY/ssh1login-server.c rename to 0.73_My_PuTTY/ssh1login-server.c diff --git a/0.72_My_PuTTY/ssh1login.c b/0.73_My_PuTTY/ssh1login.c similarity index 99% rename from 0.72_My_PuTTY/ssh1login.c rename to 0.73_My_PuTTY/ssh1login.c index fc6f990..7255e17 100644 --- a/0.72_My_PuTTY/ssh1login.c +++ b/0.73_My_PuTTY/ssh1login.c @@ -417,7 +417,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl) return; } s->username = dupstr(s->cur_prompt->prompts[0]->result); -#ifdef PERSOPORT +#ifdef MOD_PERSO SetUsernameInConfig( s->username ) ; #endif free_prompts(s->cur_prompt); @@ -461,7 +461,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl) if (!s->privatekey_available) ppl_logevent("Key file contains public key only"); s->privatekey_encrypted = rsa_ssh1_encrypted(s->keyfile, NULL); -#ifdef WINCRYPTPORT +#ifdef MOD_WINCRYPT #ifdef USE_CAPI if(s->publickey_comment && 0 == strncmp("cert://", s->publickey_comment, 7)) { sfree(s->keyfile->path); diff --git a/0.72_My_PuTTY/ssh2bpp-bare.c b/0.73_My_PuTTY/ssh2bpp-bare.c similarity index 100% rename from 0.72_My_PuTTY/ssh2bpp-bare.c rename to 0.73_My_PuTTY/ssh2bpp-bare.c diff --git a/0.72_My_PuTTY/ssh2bpp.c b/0.73_My_PuTTY/ssh2bpp.c similarity index 100% rename from 0.72_My_PuTTY/ssh2bpp.c rename to 0.73_My_PuTTY/ssh2bpp.c diff --git a/0.72_My_PuTTY/ssh2censor.c b/0.73_My_PuTTY/ssh2censor.c similarity index 100% rename from 0.72_My_PuTTY/ssh2censor.c rename to 0.73_My_PuTTY/ssh2censor.c diff --git a/0.72_My_PuTTY/ssh2connection-client.c b/0.73_My_PuTTY/ssh2connection-client.c similarity index 100% rename from 0.72_My_PuTTY/ssh2connection-client.c rename to 0.73_My_PuTTY/ssh2connection-client.c diff --git a/0.72_My_PuTTY/ssh2connection-server.c b/0.73_My_PuTTY/ssh2connection-server.c similarity index 100% rename from 0.72_My_PuTTY/ssh2connection-server.c rename to 0.73_My_PuTTY/ssh2connection-server.c diff --git a/0.72_My_PuTTY/ssh2connection.c b/0.73_My_PuTTY/ssh2connection.c similarity index 97% rename from 0.72_My_PuTTY/ssh2connection.c rename to 0.73_My_PuTTY/ssh2connection.c index 6175e05..f118af5 100644 --- a/0.72_My_PuTTY/ssh2connection.c +++ b/0.73_My_PuTTY/ssh2connection.c @@ -1,1746 +1,1746 @@ -/* - * Packet protocol layer for the SSH-2 connection protocol (RFC 4254). - */ - -#include - -#include "putty.h" -#include "ssh.h" -#include "sshbpp.h" -#include "sshppl.h" -#include "sshchan.h" -#include "sshcr.h" -#include "ssh2connection.h" - -static void ssh2_connection_free(PacketProtocolLayer *); -static void ssh2_connection_process_queue(PacketProtocolLayer *); -static bool ssh2_connection_get_specials( - PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx); -static void ssh2_connection_special_cmd(PacketProtocolLayer *ppl, - SessionSpecialCode code, int arg); -static bool ssh2_connection_want_user_input(PacketProtocolLayer *ppl); -static void ssh2_connection_got_user_input(PacketProtocolLayer *ppl); -static void ssh2_connection_reconfigure(PacketProtocolLayer *ppl, Conf *conf); - -static const struct PacketProtocolLayerVtable ssh2_connection_vtable = { - ssh2_connection_free, - ssh2_connection_process_queue, - ssh2_connection_get_specials, - ssh2_connection_special_cmd, - ssh2_connection_want_user_input, - ssh2_connection_got_user_input, - ssh2_connection_reconfigure, - "ssh-connection", -}; - -static SshChannel *ssh2_lportfwd_open( - ConnectionLayer *cl, const char *hostname, int port, - const char *description, const SocketPeerInfo *pi, Channel *chan); -static struct X11FakeAuth *ssh2_add_x11_display( - ConnectionLayer *cl, int authtype, struct X11Display *x11disp); -static struct X11FakeAuth *ssh2_add_sharing_x11_display( - ConnectionLayer *cl, int authtype, ssh_sharing_connstate *share_cs, - share_channel *share_chan); -static void ssh2_remove_sharing_x11_display(ConnectionLayer *cl, - struct X11FakeAuth *auth); -static void ssh2_send_packet_from_downstream( - ConnectionLayer *cl, unsigned id, int type, - const void *pkt, int pktlen, const char *additional_log_text); -static unsigned ssh2_alloc_sharing_channel( - ConnectionLayer *cl, ssh_sharing_connstate *connstate); -static void ssh2_delete_sharing_channel( - ConnectionLayer *cl, unsigned localid); -static void ssh2_sharing_queue_global_request( - ConnectionLayer *cl, ssh_sharing_connstate *share_ctx); -static void ssh2_sharing_no_more_downstreams(ConnectionLayer *cl); -static bool ssh2_agent_forwarding_permitted(ConnectionLayer *cl); -static void ssh2_terminal_size(ConnectionLayer *cl, int width, int height); -static void ssh2_stdout_unthrottle(ConnectionLayer *cl, size_t bufsize); -static size_t ssh2_stdin_backlog(ConnectionLayer *cl); -static void ssh2_throttle_all_channels(ConnectionLayer *cl, bool throttled); -static bool ssh2_ldisc_option(ConnectionLayer *cl, int option); -static void ssh2_set_ldisc_option(ConnectionLayer *cl, int option, bool value); -static void ssh2_enable_x_fwd(ConnectionLayer *cl); -static void ssh2_enable_agent_fwd(ConnectionLayer *cl); -static void ssh2_set_wants_user_input(ConnectionLayer *cl, bool wanted); - -static const struct ConnectionLayerVtable ssh2_connlayer_vtable = { - ssh2_rportfwd_alloc, - ssh2_rportfwd_remove, - ssh2_lportfwd_open, - ssh2_session_open, - ssh2_serverside_x11_open, - ssh2_serverside_agent_open, - ssh2_add_x11_display, - ssh2_add_sharing_x11_display, - ssh2_remove_sharing_x11_display, - ssh2_send_packet_from_downstream, - ssh2_alloc_sharing_channel, - ssh2_delete_sharing_channel, - ssh2_sharing_queue_global_request, - ssh2_sharing_no_more_downstreams, - ssh2_agent_forwarding_permitted, - ssh2_terminal_size, - ssh2_stdout_unthrottle, - ssh2_stdin_backlog, - ssh2_throttle_all_channels, - ssh2_ldisc_option, - ssh2_set_ldisc_option, - ssh2_enable_x_fwd, - ssh2_enable_agent_fwd, - ssh2_set_wants_user_input, -}; - -static char *ssh2_channel_open_failure_error_text(PktIn *pktin) -{ - static const char *const reasons[] = { - NULL, - "Administratively prohibited", - "Connect failed", - "Unknown channel type", - "Resource shortage", - }; - unsigned reason_code; - const char *reason_code_string; - char reason_code_buf[256]; - ptrlen reason; - - reason_code = get_uint32(pktin); - if (reason_code < lenof(reasons) && reasons[reason_code]) { - reason_code_string = reasons[reason_code]; - } else { - reason_code_string = reason_code_buf; - sprintf(reason_code_buf, "unknown reason code %#x", reason_code); - } - - reason = get_string(pktin); - - return dupprintf("%s [%.*s]", reason_code_string, PTRLEN_PRINTF(reason)); -} - -static size_t ssh2channel_write( - SshChannel *c, bool is_stderr, const void *buf, size_t len); -static void ssh2channel_write_eof(SshChannel *c); -static void ssh2channel_initiate_close(SshChannel *c, const char *err); -static void ssh2channel_unthrottle(SshChannel *c, size_t bufsize); -static Conf *ssh2channel_get_conf(SshChannel *c); -static void ssh2channel_window_override_removed(SshChannel *c); -static void ssh2channel_x11_sharing_handover( - SshChannel *c, ssh_sharing_connstate *share_cs, share_channel *share_chan, - const char *peer_addr, int peer_port, int endian, - int protomajor, int protominor, const void *initial_data, int initial_len); -static void ssh2channel_hint_channel_is_simple(SshChannel *c); - -static const struct SshChannelVtable ssh2channel_vtable = { - ssh2channel_write, - ssh2channel_write_eof, - ssh2channel_initiate_close, - ssh2channel_unthrottle, - ssh2channel_get_conf, - ssh2channel_window_override_removed, - ssh2channel_x11_sharing_handover, - ssh2channel_send_exit_status, - ssh2channel_send_exit_signal, - ssh2channel_send_exit_signal_numeric, - ssh2channel_request_x11_forwarding, - ssh2channel_request_agent_forwarding, - ssh2channel_request_pty, - ssh2channel_send_env_var, - ssh2channel_start_shell, - ssh2channel_start_command, - ssh2channel_start_subsystem, - ssh2channel_send_serial_break, - ssh2channel_send_signal, - ssh2channel_send_terminal_size_change, - ssh2channel_hint_channel_is_simple, -}; - -static void ssh2_channel_check_close(struct ssh2_channel *c); -static void ssh2_channel_try_eof(struct ssh2_channel *c); -static void ssh2_set_window(struct ssh2_channel *c, int newwin); -static size_t ssh2_try_send(struct ssh2_channel *c); -static void ssh2_try_send_and_unthrottle(struct ssh2_channel *c); -static void ssh2_channel_check_throttle(struct ssh2_channel *c); -static void ssh2_channel_close_local(struct ssh2_channel *c, - const char *reason); -static void ssh2_channel_destroy(struct ssh2_channel *c); - -static void ssh2_check_termination(struct ssh2_connection_state *s); - -struct outstanding_global_request { - gr_handler_fn_t handler; - void *ctx; - struct outstanding_global_request *next; -}; -void ssh2_queue_global_request_handler( - struct ssh2_connection_state *s, gr_handler_fn_t handler, void *ctx) -{ - struct outstanding_global_request *ogr = - snew(struct outstanding_global_request); - ogr->handler = handler; - ogr->ctx = ctx; - if (s->globreq_tail) - s->globreq_tail->next = ogr; - else - s->globreq_head = ogr; - s->globreq_tail = ogr; -} - -static int ssh2_channelcmp(void *av, void *bv) -{ - const struct ssh2_channel *a = (const struct ssh2_channel *) av; - const struct ssh2_channel *b = (const struct ssh2_channel *) bv; - if (a->localid < b->localid) - return -1; - if (a->localid > b->localid) - return +1; - return 0; -} - -static int ssh2_channelfind(void *av, void *bv) -{ - const unsigned *a = (const unsigned *) av; - const struct ssh2_channel *b = (const struct ssh2_channel *) bv; - if (*a < b->localid) - return -1; - if (*a > b->localid) - return +1; - return 0; -} - -/* - * Each channel has a queue of outstanding CHANNEL_REQUESTS and their - * handlers. - */ -struct outstanding_channel_request { - cr_handler_fn_t handler; - void *ctx; - struct outstanding_channel_request *next; -}; - -static void ssh2_channel_free(struct ssh2_channel *c) -{ - bufchain_clear(&c->outbuffer); - bufchain_clear(&c->errbuffer); - while (c->chanreq_head) { - struct outstanding_channel_request *chanreq = c->chanreq_head; - c->chanreq_head = c->chanreq_head->next; - sfree(chanreq); - } - if (c->chan) { - struct ssh2_connection_state *s = c->connlayer; - if (s->mainchan_sc == &c->sc) { - s->mainchan = NULL; - s->mainchan_sc = NULL; - } - chan_free(c->chan); - } - sfree(c); -} - -PacketProtocolLayer *ssh2_connection_new( - Ssh *ssh, ssh_sharing_state *connshare, bool is_simple, - Conf *conf, const char *peer_verstring, ConnectionLayer **cl_out) -{ - struct ssh2_connection_state *s = snew(struct ssh2_connection_state); - memset(s, 0, sizeof(*s)); - s->ppl.vt = &ssh2_connection_vtable; - - s->conf = conf_copy(conf); - - s->ssh_is_simple = is_simple; - - /* - * If the ssh_no_shell option is enabled, we disable the usual - * termination check, so that we persist even in the absence of - * any at all channels (because our purpose is probably to be a - * background port forwarder). - */ - s->persistent = conf_get_bool(s->conf, CONF_ssh_no_shell); - - s->connshare = connshare; - s->peer_verstring = dupstr(peer_verstring); - - s->channels = newtree234(ssh2_channelcmp); - - s->x11authtree = newtree234(x11_authcmp); - - /* Need to get the log context for s->cl now, because we won't be - * helpfully notified when a copy is written into s->ppl by our - * owner. */ - s->cl.vt = &ssh2_connlayer_vtable; - s->cl.logctx = ssh_get_logctx(ssh); - - s->portfwdmgr = portfwdmgr_new(&s->cl); - - *cl_out = &s->cl; - if (s->connshare) - ssh_connshare_provide_connlayer(s->connshare, &s->cl); - - return &s->ppl; -} - -static void ssh2_connection_free(PacketProtocolLayer *ppl) -{ - struct ssh2_connection_state *s = - container_of(ppl, struct ssh2_connection_state, ppl); - struct X11FakeAuth *auth; - struct ssh2_channel *c; - struct ssh_rportfwd *rpf; - - sfree(s->peer_verstring); - - conf_free(s->conf); - - while ((c = delpos234(s->channels, 0)) != NULL) - ssh2_channel_free(c); - freetree234(s->channels); - - while ((auth = delpos234(s->x11authtree, 0)) != NULL) { - if (auth->disp) - x11_free_display(auth->disp); - x11_free_fake_auth(auth); - } - freetree234(s->x11authtree); - - if (s->rportfwds) { - while ((rpf = delpos234(s->rportfwds, 0)) != NULL) - free_rportfwd(rpf); - freetree234(s->rportfwds); - } - portfwdmgr_free(s->portfwdmgr); - - if (s->antispoof_prompt) - free_prompts(s->antispoof_prompt); - - delete_callbacks_for_context(s); - - sfree(s); -} - -static bool ssh2_connection_filter_queue(struct ssh2_connection_state *s) -{ - PktIn *pktin; - PktOut *pktout; - ptrlen type, data; - struct ssh2_channel *c; - struct outstanding_channel_request *ocr; - unsigned localid, remid, winsize, pktsize, ext_type; - bool want_reply, reply_success, expect_halfopen; - ChanopenResult chanopen_result; - PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */ - - while (1) { - if (ssh2_common_filter_queue(&s->ppl)) - return true; - if ((pktin = pq_peek(s->ppl.in_pq)) == NULL) - return false; - - switch (pktin->type) { - case SSH2_MSG_GLOBAL_REQUEST: - type = get_string(pktin); - want_reply = get_bool(pktin); - - reply_success = ssh2_connection_parse_global_request( - s, type, pktin); - - if (want_reply) { - int type = (reply_success ? SSH2_MSG_REQUEST_SUCCESS : - SSH2_MSG_REQUEST_FAILURE); - pktout = ssh_bpp_new_pktout(s->ppl.bpp, type); - pq_push(s->ppl.out_pq, pktout); - } - pq_pop(s->ppl.in_pq); - break; - - case SSH2_MSG_REQUEST_SUCCESS: - case SSH2_MSG_REQUEST_FAILURE: - if (!s->globreq_head) { - ssh_proto_error( - s->ppl.ssh, - "Received %s with no outstanding global request", - ssh2_pkt_type(s->ppl.bpp->pls->kctx, s->ppl.bpp->pls->actx, - pktin->type)); - return true; - } - - s->globreq_head->handler(s, pktin, s->globreq_head->ctx); - { - struct outstanding_global_request *tmp = s->globreq_head; - s->globreq_head = s->globreq_head->next; - sfree(tmp); - } - - pq_pop(s->ppl.in_pq); - break; - - case SSH2_MSG_CHANNEL_OPEN: - type = get_string(pktin); - c = snew(struct ssh2_channel); - c->connlayer = s; - c->chan = NULL; - - remid = get_uint32(pktin); - winsize = get_uint32(pktin); - pktsize = get_uint32(pktin); - - chanopen_result = ssh2_connection_parse_channel_open( - s, type, pktin, &c->sc); - - if (chanopen_result.outcome == CHANOPEN_RESULT_DOWNSTREAM) { - /* - * This channel-open request needs to go to a - * connection-sharing downstream, so abandon our own - * channel-open procedure and just pass the message on - * to sshshare.c. - */ - share_got_pkt_from_server( - chanopen_result.u.downstream.share_ctx, pktin->type, - BinarySource_UPCAST(pktin)->data, - BinarySource_UPCAST(pktin)->len); - sfree(c); - break; - } - - c->remoteid = remid; - c->halfopen = false; - if (chanopen_result.outcome == CHANOPEN_RESULT_FAILURE) { - pktout = ssh_bpp_new_pktout( - s->ppl.bpp, SSH2_MSG_CHANNEL_OPEN_FAILURE); - put_uint32(pktout, c->remoteid); - put_uint32(pktout, chanopen_result.u.failure.reason_code); - put_stringz(pktout, chanopen_result.u.failure.wire_message); - put_stringz(pktout, "en"); /* language tag */ - pq_push(s->ppl.out_pq, pktout); - ppl_logevent("Rejected channel open: %s", - chanopen_result.u.failure.wire_message); - sfree(chanopen_result.u.failure.wire_message); - sfree(c); - } else { - c->chan = chanopen_result.u.success.channel; - ssh2_channel_init(c); - c->remwindow = winsize; - c->remmaxpkt = pktsize; - if (c->remmaxpkt > s->ppl.bpp->vt->packet_size_limit) - c->remmaxpkt = s->ppl.bpp->vt->packet_size_limit; - if (c->chan->initial_fixed_window_size) { - c->locwindow = c->locmaxwin = c->remlocwin = - c->chan->initial_fixed_window_size; - } - pktout = ssh_bpp_new_pktout( - s->ppl.bpp, SSH2_MSG_CHANNEL_OPEN_CONFIRMATION); - put_uint32(pktout, c->remoteid); - put_uint32(pktout, c->localid); - put_uint32(pktout, c->locwindow); - put_uint32(pktout, OUR_V2_MAXPKT); /* our max pkt size */ - pq_push(s->ppl.out_pq, pktout); - } - - pq_pop(s->ppl.in_pq); - break; - - case SSH2_MSG_CHANNEL_DATA: - case SSH2_MSG_CHANNEL_EXTENDED_DATA: - case SSH2_MSG_CHANNEL_WINDOW_ADJUST: - case SSH2_MSG_CHANNEL_REQUEST: - case SSH2_MSG_CHANNEL_EOF: - case SSH2_MSG_CHANNEL_CLOSE: - case SSH2_MSG_CHANNEL_OPEN_CONFIRMATION: - case SSH2_MSG_CHANNEL_OPEN_FAILURE: - case SSH2_MSG_CHANNEL_SUCCESS: - case SSH2_MSG_CHANNEL_FAILURE: - /* - * Common preliminary code for all the messages from the - * server that cite one of our channel ids: look up that - * channel id, check it exists, and if it's for a sharing - * downstream, pass it on. - */ - localid = get_uint32(pktin); - c = find234(s->channels, &localid, ssh2_channelfind); - - if (c && c->sharectx) { - share_got_pkt_from_server(c->sharectx, pktin->type, - BinarySource_UPCAST(pktin)->data, - BinarySource_UPCAST(pktin)->len); - pq_pop(s->ppl.in_pq); - break; - } - - expect_halfopen = ( - pktin->type == SSH2_MSG_CHANNEL_OPEN_CONFIRMATION || - pktin->type == SSH2_MSG_CHANNEL_OPEN_FAILURE); - - if (!c || c->halfopen != expect_halfopen) { - ssh_proto_error(s->ppl.ssh, - "Received %s for %s channel %u", - ssh2_pkt_type(s->ppl.bpp->pls->kctx, - s->ppl.bpp->pls->actx, - pktin->type), - (!c ? "nonexistent" : - c->halfopen ? "half-open" : "open"), - localid); - return true; - } - - switch (pktin->type) { - case SSH2_MSG_CHANNEL_OPEN_CONFIRMATION: - assert(c->halfopen); - c->remoteid = get_uint32(pktin); - c->halfopen = false; - c->remwindow = get_uint32(pktin); - c->remmaxpkt = get_uint32(pktin); - if (c->remmaxpkt > s->ppl.bpp->vt->packet_size_limit) - c->remmaxpkt = s->ppl.bpp->vt->packet_size_limit; - - chan_open_confirmation(c->chan); - - /* - * Now that the channel is fully open, it's possible - * in principle to immediately close it. Check whether - * it wants us to! - * - * This can occur if a local socket error occurred - * between us sending out CHANNEL_OPEN and receiving - * OPEN_CONFIRMATION. If that happens, all we can do - * is immediately initiate close proceedings now that - * we know the server's id to put in the close - * message. We'll have handled that in this code by - * having already turned c->chan into a zombie, so its - * want_close method (which ssh2_channel_check_close - * will consult) will already be returning true. - */ - ssh2_channel_check_close(c); - - if (c->pending_eof) - ssh2_channel_try_eof(c); /* in case we had a pending EOF */ - break; - - case SSH2_MSG_CHANNEL_OPEN_FAILURE: - assert(c->halfopen); - - { - char *err = ssh2_channel_open_failure_error_text(pktin); - chan_open_failed(c->chan, err); - sfree(err); - } - - del234(s->channels, c); - ssh2_channel_free(c); - - break; - - case SSH2_MSG_CHANNEL_DATA: - case SSH2_MSG_CHANNEL_EXTENDED_DATA: - ext_type = (pktin->type == SSH2_MSG_CHANNEL_DATA ? 0 : - get_uint32(pktin)); - data = get_string(pktin); - if (!get_err(pktin)) { - int bufsize; - c->locwindow -= data.len; - c->remlocwin -= data.len; - if (ext_type != 0 && ext_type != SSH2_EXTENDED_DATA_STDERR) - data.len = 0; /* ignore unknown extended data */ - bufsize = chan_send( - c->chan, ext_type == SSH2_EXTENDED_DATA_STDERR, - data.ptr, data.len); - - /* - * The channel may have turned into a connection- - * shared one as a result of that chan_send, e.g. - * if the data we just provided completed the X11 - * auth phase and caused a callback to - * x11_sharing_handover. If so, do nothing - * further. - */ - if (c->sharectx) - break; - - /* - * If it looks like the remote end hit the end of - * its window, and we didn't want it to do that, - * think about using a larger window. - */ - if (c->remlocwin <= 0 && - c->throttle_state == UNTHROTTLED && - c->locmaxwin < 0x40000000) - c->locmaxwin += OUR_V2_WINSIZE; - - /* - * If we are not buffering too much data, enlarge - * the window again at the remote side. If we are - * buffering too much, we may still need to adjust - * the window if the server's sent excess data. - */ - if (bufsize < c->locmaxwin) - ssh2_set_window(c, c->locmaxwin - bufsize); - - /* - * If we're either buffering way too much data, or - * if we're buffering anything at all and we're in - * "simple" mode, throttle the whole channel. - */ - if ((bufsize > c->locmaxwin || - (s->ssh_is_simple && bufsize>0)) && - !c->throttling_conn) { - c->throttling_conn = true; - ssh_throttle_conn(s->ppl.ssh, +1); - } - } - break; - - case SSH2_MSG_CHANNEL_WINDOW_ADJUST: - if (!(c->closes & CLOSES_SENT_EOF)) { - c->remwindow += get_uint32(pktin); - ssh2_try_send_and_unthrottle(c); - } - break; - - case SSH2_MSG_CHANNEL_REQUEST: - type = get_string(pktin); - want_reply = get_bool(pktin); - - reply_success = false; - - if (c->closes & CLOSES_SENT_CLOSE) { - /* - * We don't reply to channel requests after we've - * sent CHANNEL_CLOSE for the channel, because our - * reply might cross in the network with the other - * side's CHANNEL_CLOSE and arrive after they have - * wound the channel up completely. - */ - want_reply = false; - } - - /* - * Try every channel request name we recognise, no - * matter what the channel, and see if the Channel - * instance will accept it. - */ - if (ptrlen_eq_string(type, "exit-status")) { - int exitcode = toint(get_uint32(pktin)); - reply_success = chan_rcvd_exit_status(c->chan, exitcode); - } else if (ptrlen_eq_string(type, "exit-signal")) { - ptrlen signame; - int signum; - bool core = false; - ptrlen errmsg; - int format; - - /* - * ICK: older versions of OpenSSH (e.g. 3.4p1) - * provide an `int' for the signal, despite its - * having been a `string' in the drafts of RFC - * 4254 since at least 2001. (Fixed in session.c - * 1.147.) Try to infer which we can safely parse - * it as. - */ - - size_t startpos = BinarySource_UPCAST(pktin)->pos; - - for (format = 0; format < 2; format++) { - BinarySource_UPCAST(pktin)->pos = startpos; - BinarySource_UPCAST(pktin)->err = BSE_NO_ERROR; - - /* placate compiler warnings about unin */ - signame = make_ptrlen(NULL, 0); - signum = 0; - - if (format == 0) /* standard string-based format */ - signame = get_string(pktin); - else /* nonstandard integer format */ - signum = toint(get_uint32(pktin)); - - core = get_bool(pktin); - errmsg = get_string(pktin); /* error message */ - get_string(pktin); /* language tag */ - - if (!get_err(pktin) && get_avail(pktin) == 0) - break; /* successful parse */ - } - - switch (format) { - case 0: - reply_success = chan_rcvd_exit_signal( - c->chan, signame, core, errmsg); - break; - case 1: - reply_success = chan_rcvd_exit_signal_numeric( - c->chan, signum, core, errmsg); - break; - default: - /* Couldn't parse this message in either format */ - reply_success = false; - break; - } - } else if (ptrlen_eq_string(type, "shell")) { - reply_success = chan_run_shell(c->chan); - } else if (ptrlen_eq_string(type, "exec")) { - ptrlen command = get_string(pktin); - reply_success = chan_run_command(c->chan, command); - } else if (ptrlen_eq_string(type, "subsystem")) { - ptrlen subsys = get_string(pktin); - reply_success = chan_run_subsystem(c->chan, subsys); - } else if (ptrlen_eq_string(type, "x11-req")) { - bool oneshot = get_bool(pktin); - ptrlen authproto = get_string(pktin); - ptrlen authdata = get_string(pktin); - unsigned screen_number = get_uint32(pktin); - reply_success = chan_enable_x11_forwarding( - c->chan, oneshot, authproto, authdata, screen_number); - } else if (ptrlen_eq_string(type, - "auth-agent-req@openssh.com")) { - reply_success = chan_enable_agent_forwarding(c->chan); - } else if (ptrlen_eq_string(type, "pty-req")) { - ptrlen termtype = get_string(pktin); - unsigned width = get_uint32(pktin); - unsigned height = get_uint32(pktin); - unsigned pixwidth = get_uint32(pktin); - unsigned pixheight = get_uint32(pktin); - ptrlen encoded_modes = get_string(pktin); - BinarySource bs_modes[1]; - struct ssh_ttymodes modes; - - BinarySource_BARE_INIT_PL(bs_modes, encoded_modes); - modes = read_ttymodes_from_packet(bs_modes, 2); - if (get_err(bs_modes) || get_avail(bs_modes) > 0) { - ppl_logevent("Unable to decode terminal mode string"); - reply_success = false; - } else { - reply_success = chan_allocate_pty( - c->chan, termtype, width, height, - pixwidth, pixheight, modes); - } - } else if (ptrlen_eq_string(type, "env")) { - ptrlen var = get_string(pktin); - ptrlen value = get_string(pktin); - - reply_success = chan_set_env(c->chan, var, value); - } else if (ptrlen_eq_string(type, "break")) { - unsigned length = get_uint32(pktin); - - reply_success = chan_send_break(c->chan, length); - } else if (ptrlen_eq_string(type, "signal")) { - ptrlen signame = get_string(pktin); - - reply_success = chan_send_signal(c->chan, signame); - } else if (ptrlen_eq_string(type, "window-change")) { - unsigned width = get_uint32(pktin); - unsigned height = get_uint32(pktin); - unsigned pixwidth = get_uint32(pktin); - unsigned pixheight = get_uint32(pktin); - reply_success = chan_change_window_size( - c->chan, width, height, pixwidth, pixheight); - } - if (want_reply) { - int type = (reply_success ? SSH2_MSG_CHANNEL_SUCCESS : - SSH2_MSG_CHANNEL_FAILURE); - pktout = ssh_bpp_new_pktout(s->ppl.bpp, type); - put_uint32(pktout, c->remoteid); - pq_push(s->ppl.out_pq, pktout); - } - break; - - case SSH2_MSG_CHANNEL_SUCCESS: - case SSH2_MSG_CHANNEL_FAILURE: - ocr = c->chanreq_head; - if (!ocr) { - ssh_proto_error( - s->ppl.ssh, - "Received %s for channel %d with no outstanding " - "channel request", - ssh2_pkt_type(s->ppl.bpp->pls->kctx, - s->ppl.bpp->pls->actx, pktin->type)); - return true; - } - ocr->handler(c, pktin, ocr->ctx); - c->chanreq_head = ocr->next; - sfree(ocr); - /* - * We may now initiate channel-closing procedures, if - * that CHANNEL_REQUEST was the last thing outstanding - * before we send CHANNEL_CLOSE. - */ - ssh2_channel_check_close(c); - break; - - case SSH2_MSG_CHANNEL_EOF: - if (!(c->closes & CLOSES_RCVD_EOF)) { - c->closes |= CLOSES_RCVD_EOF; - chan_send_eof(c->chan); - ssh2_channel_check_close(c); - } - break; - - case SSH2_MSG_CHANNEL_CLOSE: - /* - * When we receive CLOSE on a channel, we assume it - * comes with an implied EOF if we haven't seen EOF - * yet. - */ - if (!(c->closes & CLOSES_RCVD_EOF)) { - c->closes |= CLOSES_RCVD_EOF; - chan_send_eof(c->chan); - } - - if (!(s->ppl.remote_bugs & BUG_SENDS_LATE_REQUEST_REPLY)) { - /* - * It also means we stop expecting to see replies - * to any outstanding channel requests, so clean - * those up too. (ssh_chanreq_init will enforce by - * assertion that we don't subsequently put - * anything back on this list.) - */ - while (c->chanreq_head) { - struct outstanding_channel_request *ocr = - c->chanreq_head; - ocr->handler(c, NULL, ocr->ctx); - c->chanreq_head = ocr->next; - sfree(ocr); - } - } - - /* - * And we also send an outgoing EOF, if we haven't - * already, on the assumption that CLOSE is a pretty - * forceful announcement that the remote side is doing - * away with the entire channel. (If it had wanted to - * send us EOF and continue receiving data from us, it - * would have just sent CHANNEL_EOF.) - */ - if (!(c->closes & CLOSES_SENT_EOF)) { - /* - * Abandon any buffered data we still wanted to - * send to this channel. Receiving a CHANNEL_CLOSE - * is an indication that the server really wants - * to get on and _destroy_ this channel, and it - * isn't going to send us any further - * WINDOW_ADJUSTs to permit us to send pending - * stuff. - */ - bufchain_clear(&c->outbuffer); - bufchain_clear(&c->errbuffer); - - /* - * Send outgoing EOF. - */ - sshfwd_write_eof(&c->sc); - - /* - * Make sure we don't read any more from whatever - * our local data source is for this channel. - * (This will pick up on the changes made by - * sshfwd_write_eof.) - */ - ssh2_channel_check_throttle(c); - } - - /* - * Now process the actual close. - */ - if (!(c->closes & CLOSES_RCVD_CLOSE)) { - c->closes |= CLOSES_RCVD_CLOSE; - ssh2_channel_check_close(c); - } - - break; - } - - pq_pop(s->ppl.in_pq); - break; - - default: - return false; - } - } -} - -static void ssh2_handle_winadj_response(struct ssh2_channel *c, - PktIn *pktin, void *ctx) -{ - unsigned *sizep = ctx; - - /* - * Winadj responses should always be failures. However, at least - * one server ("boks_sshd") is known to return SUCCESS for channel - * requests it's never heard of, such as "winadj@putty". Raised - * with foxt.com as bug 090916-090424, but for the sake of a quiet - * life, we don't worry about what kind of response we got. - */ - - c->remlocwin += *sizep; - sfree(sizep); - /* - * winadj messages are only sent when the window is fully open, so - * if we get an ack of one, we know any pending unthrottle is - * complete. - */ - if (c->throttle_state == UNTHROTTLING) - c->throttle_state = UNTHROTTLED; -} - -static void ssh2_set_window(struct ssh2_channel *c, int newwin) -{ - struct ssh2_connection_state *s = c->connlayer; - - /* - * Never send WINDOW_ADJUST for a channel that the remote side has - * already sent EOF on; there's no point, since it won't be - * sending any more data anyway. Ditto if _we've_ already sent - * CLOSE. - */ - if (c->closes & (CLOSES_RCVD_EOF | CLOSES_SENT_CLOSE)) - return; - - /* - * If the client-side Channel is in an initial setup phase with a - * fixed window size, e.g. for an X11 channel when we're still - * waiting to see its initial auth and may yet hand it off to a - * downstream, don't send any WINDOW_ADJUST either. - */ - if (c->chan->initial_fixed_window_size) - return; - - /* - * If the remote end has a habit of ignoring maxpkt, limit the - * window so that it has no choice (assuming it doesn't ignore the - * window as well). - */ - if ((s->ppl.remote_bugs & BUG_SSH2_MAXPKT) && newwin > OUR_V2_MAXPKT) - newwin = OUR_V2_MAXPKT; - - /* - * Only send a WINDOW_ADJUST if there's significantly more window - * available than the other end thinks there is. This saves us - * sending a WINDOW_ADJUST for every character in a shell session. - * - * "Significant" is arbitrarily defined as half the window size. - */ - if (newwin / 2 >= c->locwindow) { - PktOut *pktout; - unsigned *up; - - /* - * In order to keep track of how much window the client - * actually has available, we'd like it to acknowledge each - * WINDOW_ADJUST. We can't do that directly, so we accompany - * it with a CHANNEL_REQUEST that has to be acknowledged. - * - * This is only necessary if we're opening the window wide. - * If we're not, then throughput is being constrained by - * something other than the maximum window size anyway. - */ - if (newwin == c->locmaxwin && - !(s->ppl.remote_bugs & BUG_CHOKES_ON_WINADJ)) { - up = snew(unsigned); - *up = newwin - c->locwindow; - pktout = ssh2_chanreq_init(c, "winadj@putty.projects.tartarus.org", - ssh2_handle_winadj_response, up); - pq_push(s->ppl.out_pq, pktout); - - if (c->throttle_state != UNTHROTTLED) - c->throttle_state = UNTHROTTLING; - } else { - /* Pretend the WINDOW_ADJUST was acked immediately. */ - c->remlocwin = newwin; - c->throttle_state = THROTTLED; - } - pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_WINDOW_ADJUST); - put_uint32(pktout, c->remoteid); - put_uint32(pktout, newwin - c->locwindow); - pq_push(s->ppl.out_pq, pktout); - c->locwindow = newwin; - } -} - -static PktIn *ssh2_connection_pop(struct ssh2_connection_state *s) -{ - ssh2_connection_filter_queue(s); - return pq_pop(s->ppl.in_pq); -} - -static void ssh2_connection_process_queue(PacketProtocolLayer *ppl) -{ - struct ssh2_connection_state *s = - container_of(ppl, struct ssh2_connection_state, ppl); - PktIn *pktin; - - if (ssh2_connection_filter_queue(s)) /* no matter why we were called */ - return; - - crBegin(s->crState); - - if (s->connshare) - share_activate(s->connshare, s->peer_verstring); - - /* - * Signal the seat that authentication is done, so that it can - * deploy spoofing defences. If it doesn't have any, deploy our - * own fallback one. - * - * We do this here rather than at the end of userauth, because we - * might not have gone through userauth at all (if we're a - * connection-sharing downstream). - */ - if (ssh2_connection_need_antispoof_prompt(s)) { - s->antispoof_prompt = new_prompts(); - s->antispoof_prompt->to_server = true; - s->antispoof_prompt->from_server = false; - s->antispoof_prompt->name = dupstr("Authentication successful"); -#ifndef PERSOPORT - add_prompt( - s->antispoof_prompt, - dupstr("Access granted. Press Return to begin session. "), false); - s->antispoof_ret = seat_get_userpass_input( - s->ppl.seat, s->antispoof_prompt, NULL); -#endif - while (1) { - while (s->antispoof_ret < 0 && - bufchain_size(s->ppl.user_input) > 0) - s->antispoof_ret = seat_get_userpass_input( - s->ppl.seat, s->antispoof_prompt, s->ppl.user_input); - - if (s->antispoof_ret >= 0) - break; - - s->want_user_input = true; - crReturnV; - s->want_user_input = false; - } - free_prompts(s->antispoof_prompt); - s->antispoof_prompt = NULL; - } - - /* - * Enable port forwardings. - */ - portfwdmgr_config(s->portfwdmgr, s->conf); - s->portfwdmgr_configured = true; - - /* - * Create the main session channel, if any. - */ - s->mainchan = mainchan_new( - &s->ppl, &s->cl, s->conf, s->term_width, s->term_height, - s->ssh_is_simple, &s->mainchan_sc); - - /* - * Transfer data! - */ - - while (1) { - if ((pktin = ssh2_connection_pop(s)) != NULL) { - - /* - * _All_ the connection-layer packets we expect to - * receive are now handled by the dispatch table. - * Anything that reaches here must be bogus. - */ - - ssh_proto_error(s->ppl.ssh, "Received unexpected connection-layer " - "packet, type %d (%s)", pktin->type, - ssh2_pkt_type(s->ppl.bpp->pls->kctx, - s->ppl.bpp->pls->actx, - pktin->type)); - return; - } - crReturnV; - } - - crFinishV; -} - -static void ssh2_channel_check_close(struct ssh2_channel *c) -{ - struct ssh2_connection_state *s = c->connlayer; - PktOut *pktout; - - if (c->halfopen) { - /* - * If we've sent out our own CHANNEL_OPEN but not yet seen - * either OPEN_CONFIRMATION or OPEN_FAILURE in response, then - * it's too early to be sending close messages of any kind. - */ - return; - } - - if (chan_want_close(c->chan, (c->closes & CLOSES_SENT_EOF), - (c->closes & CLOSES_RCVD_EOF)) && - !c->chanreq_head && - !(c->closes & CLOSES_SENT_CLOSE)) { - /* - * We have both sent and received EOF (or the channel is a - * zombie), and we have no outstanding channel requests, which - * means the channel is in final wind-up. But we haven't sent - * CLOSE, so let's do so now. - */ - pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_CLOSE); - put_uint32(pktout, c->remoteid); - pq_push(s->ppl.out_pq, pktout); - c->closes |= CLOSES_SENT_EOF | CLOSES_SENT_CLOSE; - } - - if (!((CLOSES_SENT_CLOSE | CLOSES_RCVD_CLOSE) & ~c->closes)) { - assert(c->chanreq_head == NULL); - /* - * We have both sent and received CLOSE, which means we're - * completely done with the channel. - */ - ssh2_channel_destroy(c); - } -} - -static void ssh2_channel_try_eof(struct ssh2_channel *c) -{ - struct ssh2_connection_state *s = c->connlayer; - PktOut *pktout; - assert(c->pending_eof); /* precondition for calling us */ - if (c->halfopen) - return; /* can't close: not even opened yet */ - if (bufchain_size(&c->outbuffer) > 0 || bufchain_size(&c->errbuffer) > 0) - return; /* can't send EOF: pending outgoing data */ - - c->pending_eof = false; /* we're about to send it */ - - pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_EOF); - put_uint32(pktout, c->remoteid); - pq_push(s->ppl.out_pq, pktout); - c->closes |= CLOSES_SENT_EOF; - ssh2_channel_check_close(c); -} - -/* - * Attempt to send data on an SSH-2 channel. - */ -static size_t ssh2_try_send(struct ssh2_channel *c) -{ - struct ssh2_connection_state *s = c->connlayer; - PktOut *pktout; - size_t bufsize; - - if (!c->halfopen) { - while (c->remwindow > 0 && - (bufchain_size(&c->outbuffer) > 0 || - bufchain_size(&c->errbuffer) > 0)) { - bufchain *buf = (bufchain_size(&c->errbuffer) > 0 ? - &c->errbuffer : &c->outbuffer); - - ptrlen data = bufchain_prefix(buf); - if (data.len > c->remwindow) - data.len = c->remwindow; - if (data.len > c->remmaxpkt) - data.len = c->remmaxpkt; - if (buf == &c->errbuffer) { - pktout = ssh_bpp_new_pktout( - s->ppl.bpp, SSH2_MSG_CHANNEL_EXTENDED_DATA); - put_uint32(pktout, c->remoteid); - put_uint32(pktout, SSH2_EXTENDED_DATA_STDERR); - } else { - pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_DATA); - put_uint32(pktout, c->remoteid); - } - put_stringpl(pktout, data); - pq_push(s->ppl.out_pq, pktout); - bufchain_consume(buf, data.len); - c->remwindow -= data.len; - } - } - - /* - * After having sent as much data as we can, return the amount - * still buffered. - */ - bufsize = bufchain_size(&c->outbuffer) + bufchain_size(&c->errbuffer); - - /* - * And if there's no data pending but we need to send an EOF, send - * it. - */ - if (!bufsize && c->pending_eof) - ssh2_channel_try_eof(c); - - return bufsize; -} - -static void ssh2_try_send_and_unthrottle(struct ssh2_channel *c) -{ - int bufsize; - if (c->closes & CLOSES_SENT_EOF) - return; /* don't send on channels we've EOFed */ - bufsize = ssh2_try_send(c); - if (bufsize == 0) { - c->throttled_by_backlog = false; - ssh2_channel_check_throttle(c); - } -} - -static void ssh2_channel_check_throttle(struct ssh2_channel *c) -{ - /* - * We don't want this channel to read further input if this - * particular channel has a backed-up SSH window, or if the - * outgoing side of the whole SSH connection is currently - * throttled, or if this channel already has an outgoing EOF - * either sent or pending. - */ - chan_set_input_wanted(c->chan, - !c->throttled_by_backlog && - !c->connlayer->all_channels_throttled && - !c->pending_eof && - !(c->closes & CLOSES_SENT_EOF)); -} - -/* - * Close any local socket and free any local resources associated with - * a channel. This converts the channel into a zombie. - */ -static void ssh2_channel_close_local(struct ssh2_channel *c, - const char *reason) -{ - struct ssh2_connection_state *s = c->connlayer; - PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */ - char *msg = NULL; - - if (c->sharectx) - return; - - msg = chan_log_close_msg(c->chan); - - if (msg) - ppl_logevent("%s%s%s", msg, reason ? " " : "", reason ? reason : ""); - - sfree(msg); - - chan_free(c->chan); - c->chan = zombiechan_new(); -} - -static void ssh2_check_termination_callback(void *vctx) -{ - struct ssh2_connection_state *s = (struct ssh2_connection_state *)vctx; - ssh2_check_termination(s); -} - -static void ssh2_channel_destroy(struct ssh2_channel *c) -{ - struct ssh2_connection_state *s = c->connlayer; - - assert(c->chanreq_head == NULL); - - ssh2_channel_close_local(c, NULL); - del234(s->channels, c); - ssh2_channel_free(c); - - /* - * If that was the last channel left open, we might need to - * terminate. But we'll be a bit cautious, by doing that in a - * toplevel callback, just in case anything on the current call - * stack objects to this entire PPL being freed. - */ - queue_toplevel_callback(ssh2_check_termination_callback, s); -} - -static void ssh2_check_termination(struct ssh2_connection_state *s) -{ - /* - * Decide whether we should terminate the SSH connection now. - * Called after a channel or a downstream goes away. The general - * policy is that we terminate when none of either is left. - */ - - if (s->persistent) - return; /* persistent mode: never proactively terminate */ - - if (count234(s->channels) == 0 && - !(s->connshare && share_ndownstreams(s->connshare) > 0)) { - /* - * We used to send SSH_MSG_DISCONNECT here, because I'd - * believed that _every_ conforming SSH-2 connection had to - * end with a disconnect being sent by at least one side; - * apparently I was wrong and it's perfectly OK to - * unceremoniously slam the connection shut when you're done, - * and indeed OpenSSH feels this is more polite than sending a - * DISCONNECT. So now we don't. - */ - ssh_user_close(s->ppl.ssh, "All channels closed"); - return; - } -} - -/* - * Set up most of a new ssh2_channel. Nulls out sharectx, but leaves - * chan untouched (since it will sometimes have been filled in before - * calling this). - */ -void ssh2_channel_init(struct ssh2_channel *c) -{ - struct ssh2_connection_state *s = c->connlayer; - c->closes = 0; - c->pending_eof = false; - c->throttling_conn = false; - c->throttled_by_backlog = false; - c->sharectx = NULL; - c->locwindow = c->locmaxwin = c->remlocwin = - s->ssh_is_simple ? OUR_V2_BIGWIN : OUR_V2_WINSIZE; - c->chanreq_head = NULL; - c->throttle_state = UNTHROTTLED; - bufchain_init(&c->outbuffer); - bufchain_init(&c->errbuffer); - c->sc.vt = &ssh2channel_vtable; - c->sc.cl = &s->cl; - c->localid = alloc_channel_id(s->channels, struct ssh2_channel); - add234(s->channels, c); -} - -/* - * Construct the common parts of a CHANNEL_OPEN. - */ -PktOut *ssh2_chanopen_init(struct ssh2_channel *c, const char *type) -{ - struct ssh2_connection_state *s = c->connlayer; - PktOut *pktout; - - pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_OPEN); - put_stringz(pktout, type); - put_uint32(pktout, c->localid); - put_uint32(pktout, c->locwindow); /* our window size */ - put_uint32(pktout, OUR_V2_MAXPKT); /* our max pkt size */ - return pktout; -} - -/* - * Construct the common parts of a CHANNEL_REQUEST. If handler is not - * NULL then a reply will be requested and the handler will be called - * when it arrives. The returned packet is ready to have any - * request-specific data added and be sent. Note that if a handler is - * provided, it's essential that the request actually be sent. - * - * The handler will usually be passed the response packet in pktin. If - * pktin is NULL, this means that no reply will ever be forthcoming - * (e.g. because the entire connection is being destroyed, or because - * the server initiated channel closure before we saw the response) - * and the handler should free any storage it's holding. - */ -PktOut *ssh2_chanreq_init(struct ssh2_channel *c, const char *type, - cr_handler_fn_t handler, void *ctx) -{ - struct ssh2_connection_state *s = c->connlayer; - PktOut *pktout; - - assert(!(c->closes & (CLOSES_SENT_CLOSE | CLOSES_RCVD_CLOSE))); - pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_REQUEST); - put_uint32(pktout, c->remoteid); - put_stringz(pktout, type); - put_bool(pktout, handler != NULL); - if (handler != NULL) { - struct outstanding_channel_request *ocr = - snew(struct outstanding_channel_request); - - ocr->handler = handler; - ocr->ctx = ctx; - ocr->next = NULL; - if (!c->chanreq_head) - c->chanreq_head = ocr; - else - c->chanreq_tail->next = ocr; - c->chanreq_tail = ocr; - } - return pktout; -} - -static Conf *ssh2channel_get_conf(SshChannel *sc) -{ - struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); - struct ssh2_connection_state *s = c->connlayer; - return s->conf; -} - -static void ssh2channel_write_eof(SshChannel *sc) -{ - struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); - - if (c->closes & CLOSES_SENT_EOF) - return; - - c->pending_eof = true; - ssh2_channel_try_eof(c); -} - -static void ssh2channel_initiate_close(SshChannel *sc, const char *err) -{ - struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); - char *reason; - - reason = err ? dupprintf("due to local error: %s", err) : NULL; - ssh2_channel_close_local(c, reason); - sfree(reason); - c->pending_eof = false; /* this will confuse a zombie channel */ - - ssh2_channel_check_close(c); -} - -static void ssh2channel_unthrottle(SshChannel *sc, size_t bufsize) -{ - struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); - struct ssh2_connection_state *s = c->connlayer; - size_t buflimit; - - buflimit = s->ssh_is_simple ? 0 : c->locmaxwin; - if (bufsize < buflimit) - ssh2_set_window(c, buflimit - bufsize); - - if (c->throttling_conn && bufsize <= buflimit) { - c->throttling_conn = false; - ssh_throttle_conn(s->ppl.ssh, -1); - } -} - -static size_t ssh2channel_write( - SshChannel *sc, bool is_stderr, const void *buf, size_t len) -{ - struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); - assert(!(c->closes & CLOSES_SENT_EOF)); - bufchain_add(is_stderr ? &c->errbuffer : &c->outbuffer, buf, len); - return ssh2_try_send(c); -} - -static void ssh2channel_x11_sharing_handover( - SshChannel *sc, ssh_sharing_connstate *share_cs, share_channel *share_chan, - const char *peer_addr, int peer_port, int endian, - int protomajor, int protominor, const void *initial_data, int initial_len) -{ - struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); - /* - * This function is called when we've just discovered that an X - * forwarding channel on which we'd been handling the initial auth - * ourselves turns out to be destined for a connection-sharing - * downstream. So we turn the channel into a sharing one, meaning - * that we completely stop tracking windows and buffering data and - * just pass more or less unmodified SSH messages back and forth. - */ - c->sharectx = share_cs; - share_setup_x11_channel(share_cs, share_chan, - c->localid, c->remoteid, c->remwindow, - c->remmaxpkt, c->locwindow, - peer_addr, peer_port, endian, - protomajor, protominor, - initial_data, initial_len); - chan_free(c->chan); - c->chan = NULL; -} - -static void ssh2channel_window_override_removed(SshChannel *sc) -{ - struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); - struct ssh2_connection_state *s = c->connlayer; - - /* - * This function is called when a client-side Channel has just - * stopped requiring an initial fixed-size window. - */ - assert(!c->chan->initial_fixed_window_size); - ssh2_set_window(c, s->ssh_is_simple ? OUR_V2_BIGWIN : OUR_V2_WINSIZE); -} - -static void ssh2channel_hint_channel_is_simple(SshChannel *sc) -{ - struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); - struct ssh2_connection_state *s = c->connlayer; - - PktOut *pktout = ssh2_chanreq_init( - c, "simple@putty.projects.tartarus.org", NULL, NULL); - pq_push(s->ppl.out_pq, pktout); -} - -static SshChannel *ssh2_lportfwd_open( - ConnectionLayer *cl, const char *hostname, int port, - const char *description, const SocketPeerInfo *pi, Channel *chan) -{ - struct ssh2_connection_state *s = - container_of(cl, struct ssh2_connection_state, cl); - struct ssh2_channel *c = snew(struct ssh2_channel); - PktOut *pktout; - - c->connlayer = s; - ssh2_channel_init(c); - c->halfopen = true; - c->chan = chan; - - pktout = ssh2_portfwd_chanopen(s, c, hostname, port, description, pi); - pq_push(s->ppl.out_pq, pktout); - - return &c->sc; -} - -static void ssh2_sharing_globreq_response( - struct ssh2_connection_state *s, PktIn *pktin, void *ctx) -{ - ssh_sharing_connstate *cs = (ssh_sharing_connstate *)ctx; - share_got_pkt_from_server(cs, pktin->type, - BinarySource_UPCAST(pktin)->data, - BinarySource_UPCAST(pktin)->len); -} - -static void ssh2_sharing_queue_global_request( - ConnectionLayer *cl, ssh_sharing_connstate *cs) -{ - struct ssh2_connection_state *s = - container_of(cl, struct ssh2_connection_state, cl); - ssh2_queue_global_request_handler(s, ssh2_sharing_globreq_response, cs); -} - -static void ssh2_sharing_no_more_downstreams(ConnectionLayer *cl) -{ - struct ssh2_connection_state *s = - container_of(cl, struct ssh2_connection_state, cl); - queue_toplevel_callback(ssh2_check_termination_callback, s); -} - -static struct X11FakeAuth *ssh2_add_x11_display( - ConnectionLayer *cl, int authtype, struct X11Display *disp) -{ - struct ssh2_connection_state *s = - container_of(cl, struct ssh2_connection_state, cl); - struct X11FakeAuth *auth = x11_invent_fake_auth(s->x11authtree, authtype); - auth->disp = disp; - return auth; -} - -static struct X11FakeAuth *ssh2_add_sharing_x11_display( - ConnectionLayer *cl, int authtype, ssh_sharing_connstate *share_cs, - share_channel *share_chan) -{ - struct ssh2_connection_state *s = - container_of(cl, struct ssh2_connection_state, cl); - struct X11FakeAuth *auth; - - /* - * Make up a new set of fake X11 auth data, and add it to the tree - * of currently valid ones with an indication of the sharing - * context that it's relevant to. - */ - auth = x11_invent_fake_auth(s->x11authtree, authtype); - auth->share_cs = share_cs; - auth->share_chan = share_chan; - - return auth; -} - -static void ssh2_remove_sharing_x11_display( - ConnectionLayer *cl, struct X11FakeAuth *auth) -{ - struct ssh2_connection_state *s = - container_of(cl, struct ssh2_connection_state, cl); - del234(s->x11authtree, auth); - x11_free_fake_auth(auth); -} - -static unsigned ssh2_alloc_sharing_channel( - ConnectionLayer *cl, ssh_sharing_connstate *connstate) -{ - struct ssh2_connection_state *s = - container_of(cl, struct ssh2_connection_state, cl); - struct ssh2_channel *c = snew(struct ssh2_channel); - - c->connlayer = s; - ssh2_channel_init(c); - c->chan = NULL; - c->sharectx = connstate; - return c->localid; -} - -static void ssh2_delete_sharing_channel(ConnectionLayer *cl, unsigned localid) -{ - struct ssh2_connection_state *s = - container_of(cl, struct ssh2_connection_state, cl); - struct ssh2_channel *c = find234(s->channels, &localid, ssh2_channelfind); - if (c) - ssh2_channel_destroy(c); -} - -static void ssh2_send_packet_from_downstream( - ConnectionLayer *cl, unsigned id, int type, - const void *data, int datalen, const char *additional_log_text) -{ - struct ssh2_connection_state *s = - container_of(cl, struct ssh2_connection_state, cl); - PktOut *pkt = ssh_bpp_new_pktout(s->ppl.bpp, type); - pkt->downstream_id = id; - pkt->additional_log_text = additional_log_text; - put_data(pkt, data, datalen); - pq_push(s->ppl.out_pq, pkt); -} - -static bool ssh2_agent_forwarding_permitted(ConnectionLayer *cl) -{ - struct ssh2_connection_state *s = - container_of(cl, struct ssh2_connection_state, cl); - return conf_get_bool(s->conf, CONF_agentfwd) && agent_exists(); -} - -static bool ssh2_connection_get_specials( - PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx) -{ - struct ssh2_connection_state *s = - container_of(ppl, struct ssh2_connection_state, ppl); - bool toret = false; - - if (s->mainchan) { - mainchan_get_specials(s->mainchan, add_special, ctx); - toret = true; - } - - /* - * Don't bother offering IGNORE if we've decided the remote - * won't cope with it, since we wouldn't bother sending it if - * asked anyway. - */ - if (!(s->ppl.remote_bugs & BUG_CHOKES_ON_SSH2_IGNORE)) { - if (toret) - add_special(ctx, NULL, SS_SEP, 0); - - add_special(ctx, "IGNORE message", SS_NOP, 0); - toret = true; - } - - return toret; -} - -static void ssh2_connection_special_cmd(PacketProtocolLayer *ppl, - SessionSpecialCode code, int arg) -{ - struct ssh2_connection_state *s = - container_of(ppl, struct ssh2_connection_state, ppl); - PktOut *pktout; - - if (code == SS_PING || code == SS_NOP) { - if (!(s->ppl.remote_bugs & BUG_CHOKES_ON_SSH2_IGNORE)) { - pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_IGNORE); - put_stringz(pktout, ""); - pq_push(s->ppl.out_pq, pktout); - } - } else if (s->mainchan) { - mainchan_special_cmd(s->mainchan, code, arg); - } -} - -static void ssh2_terminal_size(ConnectionLayer *cl, int width, int height) -{ - struct ssh2_connection_state *s = - container_of(cl, struct ssh2_connection_state, cl); - - s->term_width = width; - s->term_height = height; - if (s->mainchan) - mainchan_terminal_size(s->mainchan, width, height); -} - -static void ssh2_stdout_unthrottle(ConnectionLayer *cl, size_t bufsize) -{ - struct ssh2_connection_state *s = - container_of(cl, struct ssh2_connection_state, cl); - - if (s->mainchan) - sshfwd_unthrottle(s->mainchan_sc, bufsize); -} - -static size_t ssh2_stdin_backlog(ConnectionLayer *cl) -{ - struct ssh2_connection_state *s = - container_of(cl, struct ssh2_connection_state, cl); - struct ssh2_channel *c; - - if (!s->mainchan) - return 0; - c = container_of(s->mainchan_sc, struct ssh2_channel, sc); - return s->mainchan ? - bufchain_size(&c->outbuffer) + bufchain_size(&c->errbuffer) : 0; -} - -static void ssh2_throttle_all_channels(ConnectionLayer *cl, bool throttled) -{ - struct ssh2_connection_state *s = - container_of(cl, struct ssh2_connection_state, cl); - struct ssh2_channel *c; - int i; - - s->all_channels_throttled = throttled; - - for (i = 0; NULL != (c = index234(s->channels, i)); i++) - if (!c->sharectx) - ssh2_channel_check_throttle(c); -} - -static bool ssh2_ldisc_option(ConnectionLayer *cl, int option) -{ - struct ssh2_connection_state *s = - container_of(cl, struct ssh2_connection_state, cl); - - return s->ldisc_opts[option]; -} - -static void ssh2_set_ldisc_option(ConnectionLayer *cl, int option, bool value) -{ - struct ssh2_connection_state *s = - container_of(cl, struct ssh2_connection_state, cl); - - s->ldisc_opts[option] = value; -} - -static void ssh2_enable_x_fwd(ConnectionLayer *cl) -{ - struct ssh2_connection_state *s = - container_of(cl, struct ssh2_connection_state, cl); - - s->X11_fwd_enabled = true; -} - -static void ssh2_enable_agent_fwd(ConnectionLayer *cl) -{ - struct ssh2_connection_state *s = - container_of(cl, struct ssh2_connection_state, cl); - - s->agent_fwd_enabled = true; -} - -static void ssh2_set_wants_user_input(ConnectionLayer *cl, bool wanted) -{ - struct ssh2_connection_state *s = - container_of(cl, struct ssh2_connection_state, cl); - - s->want_user_input = wanted; -} - -static bool ssh2_connection_want_user_input(PacketProtocolLayer *ppl) -{ - struct ssh2_connection_state *s = - container_of(ppl, struct ssh2_connection_state, ppl); - return s->want_user_input; -} - -static void ssh2_connection_got_user_input(PacketProtocolLayer *ppl) -{ - struct ssh2_connection_state *s = - container_of(ppl, struct ssh2_connection_state, ppl); - - while (s->mainchan && bufchain_size(s->ppl.user_input) > 0) { - /* - * Add user input to the main channel's buffer. - */ - ptrlen data = bufchain_prefix(s->ppl.user_input); - sshfwd_write(s->mainchan_sc, data.ptr, data.len); - bufchain_consume(s->ppl.user_input, data.len); - } -} - -static void ssh2_connection_reconfigure(PacketProtocolLayer *ppl, Conf *conf) -{ - struct ssh2_connection_state *s = - container_of(ppl, struct ssh2_connection_state, ppl); - - conf_free(s->conf); - s->conf = conf_copy(conf); - - if (s->portfwdmgr_configured) - portfwdmgr_config(s->portfwdmgr, s->conf); -} +/* + * Packet protocol layer for the SSH-2 connection protocol (RFC 4254). + */ + +#include + +#include "putty.h" +#include "ssh.h" +#include "sshbpp.h" +#include "sshppl.h" +#include "sshchan.h" +#include "sshcr.h" +#include "ssh2connection.h" + +static void ssh2_connection_free(PacketProtocolLayer *); +static void ssh2_connection_process_queue(PacketProtocolLayer *); +static bool ssh2_connection_get_specials( + PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx); +static void ssh2_connection_special_cmd(PacketProtocolLayer *ppl, + SessionSpecialCode code, int arg); +static bool ssh2_connection_want_user_input(PacketProtocolLayer *ppl); +static void ssh2_connection_got_user_input(PacketProtocolLayer *ppl); +static void ssh2_connection_reconfigure(PacketProtocolLayer *ppl, Conf *conf); + +static const struct PacketProtocolLayerVtable ssh2_connection_vtable = { + ssh2_connection_free, + ssh2_connection_process_queue, + ssh2_connection_get_specials, + ssh2_connection_special_cmd, + ssh2_connection_want_user_input, + ssh2_connection_got_user_input, + ssh2_connection_reconfigure, + "ssh-connection", +}; + +static SshChannel *ssh2_lportfwd_open( + ConnectionLayer *cl, const char *hostname, int port, + const char *description, const SocketPeerInfo *pi, Channel *chan); +static struct X11FakeAuth *ssh2_add_x11_display( + ConnectionLayer *cl, int authtype, struct X11Display *x11disp); +static struct X11FakeAuth *ssh2_add_sharing_x11_display( + ConnectionLayer *cl, int authtype, ssh_sharing_connstate *share_cs, + share_channel *share_chan); +static void ssh2_remove_sharing_x11_display(ConnectionLayer *cl, + struct X11FakeAuth *auth); +static void ssh2_send_packet_from_downstream( + ConnectionLayer *cl, unsigned id, int type, + const void *pkt, int pktlen, const char *additional_log_text); +static unsigned ssh2_alloc_sharing_channel( + ConnectionLayer *cl, ssh_sharing_connstate *connstate); +static void ssh2_delete_sharing_channel( + ConnectionLayer *cl, unsigned localid); +static void ssh2_sharing_queue_global_request( + ConnectionLayer *cl, ssh_sharing_connstate *share_ctx); +static void ssh2_sharing_no_more_downstreams(ConnectionLayer *cl); +static bool ssh2_agent_forwarding_permitted(ConnectionLayer *cl); +static void ssh2_terminal_size(ConnectionLayer *cl, int width, int height); +static void ssh2_stdout_unthrottle(ConnectionLayer *cl, size_t bufsize); +static size_t ssh2_stdin_backlog(ConnectionLayer *cl); +static void ssh2_throttle_all_channels(ConnectionLayer *cl, bool throttled); +static bool ssh2_ldisc_option(ConnectionLayer *cl, int option); +static void ssh2_set_ldisc_option(ConnectionLayer *cl, int option, bool value); +static void ssh2_enable_x_fwd(ConnectionLayer *cl); +static void ssh2_enable_agent_fwd(ConnectionLayer *cl); +static void ssh2_set_wants_user_input(ConnectionLayer *cl, bool wanted); + +static const struct ConnectionLayerVtable ssh2_connlayer_vtable = { + ssh2_rportfwd_alloc, + ssh2_rportfwd_remove, + ssh2_lportfwd_open, + ssh2_session_open, + ssh2_serverside_x11_open, + ssh2_serverside_agent_open, + ssh2_add_x11_display, + ssh2_add_sharing_x11_display, + ssh2_remove_sharing_x11_display, + ssh2_send_packet_from_downstream, + ssh2_alloc_sharing_channel, + ssh2_delete_sharing_channel, + ssh2_sharing_queue_global_request, + ssh2_sharing_no_more_downstreams, + ssh2_agent_forwarding_permitted, + ssh2_terminal_size, + ssh2_stdout_unthrottle, + ssh2_stdin_backlog, + ssh2_throttle_all_channels, + ssh2_ldisc_option, + ssh2_set_ldisc_option, + ssh2_enable_x_fwd, + ssh2_enable_agent_fwd, + ssh2_set_wants_user_input, +}; + +static char *ssh2_channel_open_failure_error_text(PktIn *pktin) +{ + static const char *const reasons[] = { + NULL, + "Administratively prohibited", + "Connect failed", + "Unknown channel type", + "Resource shortage", + }; + unsigned reason_code; + const char *reason_code_string; + char reason_code_buf[256]; + ptrlen reason; + + reason_code = get_uint32(pktin); + if (reason_code < lenof(reasons) && reasons[reason_code]) { + reason_code_string = reasons[reason_code]; + } else { + reason_code_string = reason_code_buf; + sprintf(reason_code_buf, "unknown reason code %#x", reason_code); + } + + reason = get_string(pktin); + + return dupprintf("%s [%.*s]", reason_code_string, PTRLEN_PRINTF(reason)); +} + +static size_t ssh2channel_write( + SshChannel *c, bool is_stderr, const void *buf, size_t len); +static void ssh2channel_write_eof(SshChannel *c); +static void ssh2channel_initiate_close(SshChannel *c, const char *err); +static void ssh2channel_unthrottle(SshChannel *c, size_t bufsize); +static Conf *ssh2channel_get_conf(SshChannel *c); +static void ssh2channel_window_override_removed(SshChannel *c); +static void ssh2channel_x11_sharing_handover( + SshChannel *c, ssh_sharing_connstate *share_cs, share_channel *share_chan, + const char *peer_addr, int peer_port, int endian, + int protomajor, int protominor, const void *initial_data, int initial_len); +static void ssh2channel_hint_channel_is_simple(SshChannel *c); + +static const struct SshChannelVtable ssh2channel_vtable = { + ssh2channel_write, + ssh2channel_write_eof, + ssh2channel_initiate_close, + ssh2channel_unthrottle, + ssh2channel_get_conf, + ssh2channel_window_override_removed, + ssh2channel_x11_sharing_handover, + ssh2channel_send_exit_status, + ssh2channel_send_exit_signal, + ssh2channel_send_exit_signal_numeric, + ssh2channel_request_x11_forwarding, + ssh2channel_request_agent_forwarding, + ssh2channel_request_pty, + ssh2channel_send_env_var, + ssh2channel_start_shell, + ssh2channel_start_command, + ssh2channel_start_subsystem, + ssh2channel_send_serial_break, + ssh2channel_send_signal, + ssh2channel_send_terminal_size_change, + ssh2channel_hint_channel_is_simple, +}; + +static void ssh2_channel_check_close(struct ssh2_channel *c); +static void ssh2_channel_try_eof(struct ssh2_channel *c); +static void ssh2_set_window(struct ssh2_channel *c, int newwin); +static size_t ssh2_try_send(struct ssh2_channel *c); +static void ssh2_try_send_and_unthrottle(struct ssh2_channel *c); +static void ssh2_channel_check_throttle(struct ssh2_channel *c); +static void ssh2_channel_close_local(struct ssh2_channel *c, + const char *reason); +static void ssh2_channel_destroy(struct ssh2_channel *c); + +static void ssh2_check_termination(struct ssh2_connection_state *s); + +struct outstanding_global_request { + gr_handler_fn_t handler; + void *ctx; + struct outstanding_global_request *next; +}; +void ssh2_queue_global_request_handler( + struct ssh2_connection_state *s, gr_handler_fn_t handler, void *ctx) +{ + struct outstanding_global_request *ogr = + snew(struct outstanding_global_request); + ogr->handler = handler; + ogr->ctx = ctx; + if (s->globreq_tail) + s->globreq_tail->next = ogr; + else + s->globreq_head = ogr; + s->globreq_tail = ogr; +} + +static int ssh2_channelcmp(void *av, void *bv) +{ + const struct ssh2_channel *a = (const struct ssh2_channel *) av; + const struct ssh2_channel *b = (const struct ssh2_channel *) bv; + if (a->localid < b->localid) + return -1; + if (a->localid > b->localid) + return +1; + return 0; +} + +static int ssh2_channelfind(void *av, void *bv) +{ + const unsigned *a = (const unsigned *) av; + const struct ssh2_channel *b = (const struct ssh2_channel *) bv; + if (*a < b->localid) + return -1; + if (*a > b->localid) + return +1; + return 0; +} + +/* + * Each channel has a queue of outstanding CHANNEL_REQUESTS and their + * handlers. + */ +struct outstanding_channel_request { + cr_handler_fn_t handler; + void *ctx; + struct outstanding_channel_request *next; +}; + +static void ssh2_channel_free(struct ssh2_channel *c) +{ + bufchain_clear(&c->outbuffer); + bufchain_clear(&c->errbuffer); + while (c->chanreq_head) { + struct outstanding_channel_request *chanreq = c->chanreq_head; + c->chanreq_head = c->chanreq_head->next; + sfree(chanreq); + } + if (c->chan) { + struct ssh2_connection_state *s = c->connlayer; + if (s->mainchan_sc == &c->sc) { + s->mainchan = NULL; + s->mainchan_sc = NULL; + } + chan_free(c->chan); + } + sfree(c); +} + +PacketProtocolLayer *ssh2_connection_new( + Ssh *ssh, ssh_sharing_state *connshare, bool is_simple, + Conf *conf, const char *peer_verstring, ConnectionLayer **cl_out) +{ + struct ssh2_connection_state *s = snew(struct ssh2_connection_state); + memset(s, 0, sizeof(*s)); + s->ppl.vt = &ssh2_connection_vtable; + + s->conf = conf_copy(conf); + + s->ssh_is_simple = is_simple; + + /* + * If the ssh_no_shell option is enabled, we disable the usual + * termination check, so that we persist even in the absence of + * any at all channels (because our purpose is probably to be a + * background port forwarder). + */ + s->persistent = conf_get_bool(s->conf, CONF_ssh_no_shell); + + s->connshare = connshare; + s->peer_verstring = dupstr(peer_verstring); + + s->channels = newtree234(ssh2_channelcmp); + + s->x11authtree = newtree234(x11_authcmp); + + /* Need to get the log context for s->cl now, because we won't be + * helpfully notified when a copy is written into s->ppl by our + * owner. */ + s->cl.vt = &ssh2_connlayer_vtable; + s->cl.logctx = ssh_get_logctx(ssh); + + s->portfwdmgr = portfwdmgr_new(&s->cl); + + *cl_out = &s->cl; + if (s->connshare) + ssh_connshare_provide_connlayer(s->connshare, &s->cl); + + return &s->ppl; +} + +static void ssh2_connection_free(PacketProtocolLayer *ppl) +{ + struct ssh2_connection_state *s = + container_of(ppl, struct ssh2_connection_state, ppl); + struct X11FakeAuth *auth; + struct ssh2_channel *c; + struct ssh_rportfwd *rpf; + + sfree(s->peer_verstring); + + conf_free(s->conf); + + while ((c = delpos234(s->channels, 0)) != NULL) + ssh2_channel_free(c); + freetree234(s->channels); + + while ((auth = delpos234(s->x11authtree, 0)) != NULL) { + if (auth->disp) + x11_free_display(auth->disp); + x11_free_fake_auth(auth); + } + freetree234(s->x11authtree); + + if (s->rportfwds) { + while ((rpf = delpos234(s->rportfwds, 0)) != NULL) + free_rportfwd(rpf); + freetree234(s->rportfwds); + } + portfwdmgr_free(s->portfwdmgr); + + if (s->antispoof_prompt) + free_prompts(s->antispoof_prompt); + + delete_callbacks_for_context(s); + + sfree(s); +} + +static bool ssh2_connection_filter_queue(struct ssh2_connection_state *s) +{ + PktIn *pktin; + PktOut *pktout; + ptrlen type, data; + struct ssh2_channel *c; + struct outstanding_channel_request *ocr; + unsigned localid, remid, winsize, pktsize, ext_type; + bool want_reply, reply_success, expect_halfopen; + ChanopenResult chanopen_result; + PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */ + + while (1) { + if (ssh2_common_filter_queue(&s->ppl)) + return true; + if ((pktin = pq_peek(s->ppl.in_pq)) == NULL) + return false; + + switch (pktin->type) { + case SSH2_MSG_GLOBAL_REQUEST: + type = get_string(pktin); + want_reply = get_bool(pktin); + + reply_success = ssh2_connection_parse_global_request( + s, type, pktin); + + if (want_reply) { + int type = (reply_success ? SSH2_MSG_REQUEST_SUCCESS : + SSH2_MSG_REQUEST_FAILURE); + pktout = ssh_bpp_new_pktout(s->ppl.bpp, type); + pq_push(s->ppl.out_pq, pktout); + } + pq_pop(s->ppl.in_pq); + break; + + case SSH2_MSG_REQUEST_SUCCESS: + case SSH2_MSG_REQUEST_FAILURE: + if (!s->globreq_head) { + ssh_proto_error( + s->ppl.ssh, + "Received %s with no outstanding global request", + ssh2_pkt_type(s->ppl.bpp->pls->kctx, s->ppl.bpp->pls->actx, + pktin->type)); + return true; + } + + s->globreq_head->handler(s, pktin, s->globreq_head->ctx); + { + struct outstanding_global_request *tmp = s->globreq_head; + s->globreq_head = s->globreq_head->next; + sfree(tmp); + } + + pq_pop(s->ppl.in_pq); + break; + + case SSH2_MSG_CHANNEL_OPEN: + type = get_string(pktin); + c = snew(struct ssh2_channel); + c->connlayer = s; + c->chan = NULL; + + remid = get_uint32(pktin); + winsize = get_uint32(pktin); + pktsize = get_uint32(pktin); + + chanopen_result = ssh2_connection_parse_channel_open( + s, type, pktin, &c->sc); + + if (chanopen_result.outcome == CHANOPEN_RESULT_DOWNSTREAM) { + /* + * This channel-open request needs to go to a + * connection-sharing downstream, so abandon our own + * channel-open procedure and just pass the message on + * to sshshare.c. + */ + share_got_pkt_from_server( + chanopen_result.u.downstream.share_ctx, pktin->type, + BinarySource_UPCAST(pktin)->data, + BinarySource_UPCAST(pktin)->len); + sfree(c); + break; + } + + c->remoteid = remid; + c->halfopen = false; + if (chanopen_result.outcome == CHANOPEN_RESULT_FAILURE) { + pktout = ssh_bpp_new_pktout( + s->ppl.bpp, SSH2_MSG_CHANNEL_OPEN_FAILURE); + put_uint32(pktout, c->remoteid); + put_uint32(pktout, chanopen_result.u.failure.reason_code); + put_stringz(pktout, chanopen_result.u.failure.wire_message); + put_stringz(pktout, "en"); /* language tag */ + pq_push(s->ppl.out_pq, pktout); + ppl_logevent("Rejected channel open: %s", + chanopen_result.u.failure.wire_message); + sfree(chanopen_result.u.failure.wire_message); + sfree(c); + } else { + c->chan = chanopen_result.u.success.channel; + ssh2_channel_init(c); + c->remwindow = winsize; + c->remmaxpkt = pktsize; + if (c->remmaxpkt > s->ppl.bpp->vt->packet_size_limit) + c->remmaxpkt = s->ppl.bpp->vt->packet_size_limit; + if (c->chan->initial_fixed_window_size) { + c->locwindow = c->locmaxwin = c->remlocwin = + c->chan->initial_fixed_window_size; + } + pktout = ssh_bpp_new_pktout( + s->ppl.bpp, SSH2_MSG_CHANNEL_OPEN_CONFIRMATION); + put_uint32(pktout, c->remoteid); + put_uint32(pktout, c->localid); + put_uint32(pktout, c->locwindow); + put_uint32(pktout, OUR_V2_MAXPKT); /* our max pkt size */ + pq_push(s->ppl.out_pq, pktout); + } + + pq_pop(s->ppl.in_pq); + break; + + case SSH2_MSG_CHANNEL_DATA: + case SSH2_MSG_CHANNEL_EXTENDED_DATA: + case SSH2_MSG_CHANNEL_WINDOW_ADJUST: + case SSH2_MSG_CHANNEL_REQUEST: + case SSH2_MSG_CHANNEL_EOF: + case SSH2_MSG_CHANNEL_CLOSE: + case SSH2_MSG_CHANNEL_OPEN_CONFIRMATION: + case SSH2_MSG_CHANNEL_OPEN_FAILURE: + case SSH2_MSG_CHANNEL_SUCCESS: + case SSH2_MSG_CHANNEL_FAILURE: + /* + * Common preliminary code for all the messages from the + * server that cite one of our channel ids: look up that + * channel id, check it exists, and if it's for a sharing + * downstream, pass it on. + */ + localid = get_uint32(pktin); + c = find234(s->channels, &localid, ssh2_channelfind); + + if (c && c->sharectx) { + share_got_pkt_from_server(c->sharectx, pktin->type, + BinarySource_UPCAST(pktin)->data, + BinarySource_UPCAST(pktin)->len); + pq_pop(s->ppl.in_pq); + break; + } + + expect_halfopen = ( + pktin->type == SSH2_MSG_CHANNEL_OPEN_CONFIRMATION || + pktin->type == SSH2_MSG_CHANNEL_OPEN_FAILURE); + + if (!c || c->halfopen != expect_halfopen) { + ssh_proto_error(s->ppl.ssh, + "Received %s for %s channel %u", + ssh2_pkt_type(s->ppl.bpp->pls->kctx, + s->ppl.bpp->pls->actx, + pktin->type), + (!c ? "nonexistent" : + c->halfopen ? "half-open" : "open"), + localid); + return true; + } + + switch (pktin->type) { + case SSH2_MSG_CHANNEL_OPEN_CONFIRMATION: + assert(c->halfopen); + c->remoteid = get_uint32(pktin); + c->halfopen = false; + c->remwindow = get_uint32(pktin); + c->remmaxpkt = get_uint32(pktin); + if (c->remmaxpkt > s->ppl.bpp->vt->packet_size_limit) + c->remmaxpkt = s->ppl.bpp->vt->packet_size_limit; + + chan_open_confirmation(c->chan); + + /* + * Now that the channel is fully open, it's possible + * in principle to immediately close it. Check whether + * it wants us to! + * + * This can occur if a local socket error occurred + * between us sending out CHANNEL_OPEN and receiving + * OPEN_CONFIRMATION. If that happens, all we can do + * is immediately initiate close proceedings now that + * we know the server's id to put in the close + * message. We'll have handled that in this code by + * having already turned c->chan into a zombie, so its + * want_close method (which ssh2_channel_check_close + * will consult) will already be returning true. + */ + ssh2_channel_check_close(c); + + if (c->pending_eof) + ssh2_channel_try_eof(c); /* in case we had a pending EOF */ + break; + + case SSH2_MSG_CHANNEL_OPEN_FAILURE: + assert(c->halfopen); + + { + char *err = ssh2_channel_open_failure_error_text(pktin); + chan_open_failed(c->chan, err); + sfree(err); + } + + del234(s->channels, c); + ssh2_channel_free(c); + + break; + + case SSH2_MSG_CHANNEL_DATA: + case SSH2_MSG_CHANNEL_EXTENDED_DATA: + ext_type = (pktin->type == SSH2_MSG_CHANNEL_DATA ? 0 : + get_uint32(pktin)); + data = get_string(pktin); + if (!get_err(pktin)) { + int bufsize; + c->locwindow -= data.len; + c->remlocwin -= data.len; + if (ext_type != 0 && ext_type != SSH2_EXTENDED_DATA_STDERR) + data.len = 0; /* ignore unknown extended data */ + bufsize = chan_send( + c->chan, ext_type == SSH2_EXTENDED_DATA_STDERR, + data.ptr, data.len); + + /* + * The channel may have turned into a connection- + * shared one as a result of that chan_send, e.g. + * if the data we just provided completed the X11 + * auth phase and caused a callback to + * x11_sharing_handover. If so, do nothing + * further. + */ + if (c->sharectx) + break; + + /* + * If it looks like the remote end hit the end of + * its window, and we didn't want it to do that, + * think about using a larger window. + */ + if (c->remlocwin <= 0 && + c->throttle_state == UNTHROTTLED && + c->locmaxwin < 0x40000000) + c->locmaxwin += OUR_V2_WINSIZE; + + /* + * If we are not buffering too much data, enlarge + * the window again at the remote side. If we are + * buffering too much, we may still need to adjust + * the window if the server's sent excess data. + */ + if (bufsize < c->locmaxwin) + ssh2_set_window(c, c->locmaxwin - bufsize); + + /* + * If we're either buffering way too much data, or + * if we're buffering anything at all and we're in + * "simple" mode, throttle the whole channel. + */ + if ((bufsize > c->locmaxwin || + (s->ssh_is_simple && bufsize>0)) && + !c->throttling_conn) { + c->throttling_conn = true; + ssh_throttle_conn(s->ppl.ssh, +1); + } + } + break; + + case SSH2_MSG_CHANNEL_WINDOW_ADJUST: + if (!(c->closes & CLOSES_SENT_EOF)) { + c->remwindow += get_uint32(pktin); + ssh2_try_send_and_unthrottle(c); + } + break; + + case SSH2_MSG_CHANNEL_REQUEST: + type = get_string(pktin); + want_reply = get_bool(pktin); + + reply_success = false; + + if (c->closes & CLOSES_SENT_CLOSE) { + /* + * We don't reply to channel requests after we've + * sent CHANNEL_CLOSE for the channel, because our + * reply might cross in the network with the other + * side's CHANNEL_CLOSE and arrive after they have + * wound the channel up completely. + */ + want_reply = false; + } + + /* + * Try every channel request name we recognise, no + * matter what the channel, and see if the Channel + * instance will accept it. + */ + if (ptrlen_eq_string(type, "exit-status")) { + int exitcode = toint(get_uint32(pktin)); + reply_success = chan_rcvd_exit_status(c->chan, exitcode); + } else if (ptrlen_eq_string(type, "exit-signal")) { + ptrlen signame; + int signum; + bool core = false; + ptrlen errmsg; + int format; + + /* + * ICK: older versions of OpenSSH (e.g. 3.4p1) + * provide an `int' for the signal, despite its + * having been a `string' in the drafts of RFC + * 4254 since at least 2001. (Fixed in session.c + * 1.147.) Try to infer which we can safely parse + * it as. + */ + + size_t startpos = BinarySource_UPCAST(pktin)->pos; + + for (format = 0; format < 2; format++) { + BinarySource_UPCAST(pktin)->pos = startpos; + BinarySource_UPCAST(pktin)->err = BSE_NO_ERROR; + + /* placate compiler warnings about unin */ + signame = make_ptrlen(NULL, 0); + signum = 0; + + if (format == 0) /* standard string-based format */ + signame = get_string(pktin); + else /* nonstandard integer format */ + signum = toint(get_uint32(pktin)); + + core = get_bool(pktin); + errmsg = get_string(pktin); /* error message */ + get_string(pktin); /* language tag */ + + if (!get_err(pktin) && get_avail(pktin) == 0) + break; /* successful parse */ + } + + switch (format) { + case 0: + reply_success = chan_rcvd_exit_signal( + c->chan, signame, core, errmsg); + break; + case 1: + reply_success = chan_rcvd_exit_signal_numeric( + c->chan, signum, core, errmsg); + break; + default: + /* Couldn't parse this message in either format */ + reply_success = false; + break; + } + } else if (ptrlen_eq_string(type, "shell")) { + reply_success = chan_run_shell(c->chan); + } else if (ptrlen_eq_string(type, "exec")) { + ptrlen command = get_string(pktin); + reply_success = chan_run_command(c->chan, command); + } else if (ptrlen_eq_string(type, "subsystem")) { + ptrlen subsys = get_string(pktin); + reply_success = chan_run_subsystem(c->chan, subsys); + } else if (ptrlen_eq_string(type, "x11-req")) { + bool oneshot = get_bool(pktin); + ptrlen authproto = get_string(pktin); + ptrlen authdata = get_string(pktin); + unsigned screen_number = get_uint32(pktin); + reply_success = chan_enable_x11_forwarding( + c->chan, oneshot, authproto, authdata, screen_number); + } else if (ptrlen_eq_string(type, + "auth-agent-req@openssh.com")) { + reply_success = chan_enable_agent_forwarding(c->chan); + } else if (ptrlen_eq_string(type, "pty-req")) { + ptrlen termtype = get_string(pktin); + unsigned width = get_uint32(pktin); + unsigned height = get_uint32(pktin); + unsigned pixwidth = get_uint32(pktin); + unsigned pixheight = get_uint32(pktin); + ptrlen encoded_modes = get_string(pktin); + BinarySource bs_modes[1]; + struct ssh_ttymodes modes; + + BinarySource_BARE_INIT_PL(bs_modes, encoded_modes); + modes = read_ttymodes_from_packet(bs_modes, 2); + if (get_err(bs_modes) || get_avail(bs_modes) > 0) { + ppl_logevent("Unable to decode terminal mode string"); + reply_success = false; + } else { + reply_success = chan_allocate_pty( + c->chan, termtype, width, height, + pixwidth, pixheight, modes); + } + } else if (ptrlen_eq_string(type, "env")) { + ptrlen var = get_string(pktin); + ptrlen value = get_string(pktin); + + reply_success = chan_set_env(c->chan, var, value); + } else if (ptrlen_eq_string(type, "break")) { + unsigned length = get_uint32(pktin); + + reply_success = chan_send_break(c->chan, length); + } else if (ptrlen_eq_string(type, "signal")) { + ptrlen signame = get_string(pktin); + + reply_success = chan_send_signal(c->chan, signame); + } else if (ptrlen_eq_string(type, "window-change")) { + unsigned width = get_uint32(pktin); + unsigned height = get_uint32(pktin); + unsigned pixwidth = get_uint32(pktin); + unsigned pixheight = get_uint32(pktin); + reply_success = chan_change_window_size( + c->chan, width, height, pixwidth, pixheight); + } + if (want_reply) { + int type = (reply_success ? SSH2_MSG_CHANNEL_SUCCESS : + SSH2_MSG_CHANNEL_FAILURE); + pktout = ssh_bpp_new_pktout(s->ppl.bpp, type); + put_uint32(pktout, c->remoteid); + pq_push(s->ppl.out_pq, pktout); + } + break; + + case SSH2_MSG_CHANNEL_SUCCESS: + case SSH2_MSG_CHANNEL_FAILURE: + ocr = c->chanreq_head; + if (!ocr) { + ssh_proto_error( + s->ppl.ssh, + "Received %s for channel %d with no outstanding " + "channel request", + ssh2_pkt_type(s->ppl.bpp->pls->kctx, + s->ppl.bpp->pls->actx, pktin->type)); + return true; + } + ocr->handler(c, pktin, ocr->ctx); + c->chanreq_head = ocr->next; + sfree(ocr); + /* + * We may now initiate channel-closing procedures, if + * that CHANNEL_REQUEST was the last thing outstanding + * before we send CHANNEL_CLOSE. + */ + ssh2_channel_check_close(c); + break; + + case SSH2_MSG_CHANNEL_EOF: + if (!(c->closes & CLOSES_RCVD_EOF)) { + c->closes |= CLOSES_RCVD_EOF; + chan_send_eof(c->chan); + ssh2_channel_check_close(c); + } + break; + + case SSH2_MSG_CHANNEL_CLOSE: + /* + * When we receive CLOSE on a channel, we assume it + * comes with an implied EOF if we haven't seen EOF + * yet. + */ + if (!(c->closes & CLOSES_RCVD_EOF)) { + c->closes |= CLOSES_RCVD_EOF; + chan_send_eof(c->chan); + } + + if (!(s->ppl.remote_bugs & BUG_SENDS_LATE_REQUEST_REPLY)) { + /* + * It also means we stop expecting to see replies + * to any outstanding channel requests, so clean + * those up too. (ssh_chanreq_init will enforce by + * assertion that we don't subsequently put + * anything back on this list.) + */ + while (c->chanreq_head) { + struct outstanding_channel_request *ocr = + c->chanreq_head; + ocr->handler(c, NULL, ocr->ctx); + c->chanreq_head = ocr->next; + sfree(ocr); + } + } + + /* + * And we also send an outgoing EOF, if we haven't + * already, on the assumption that CLOSE is a pretty + * forceful announcement that the remote side is doing + * away with the entire channel. (If it had wanted to + * send us EOF and continue receiving data from us, it + * would have just sent CHANNEL_EOF.) + */ + if (!(c->closes & CLOSES_SENT_EOF)) { + /* + * Abandon any buffered data we still wanted to + * send to this channel. Receiving a CHANNEL_CLOSE + * is an indication that the server really wants + * to get on and _destroy_ this channel, and it + * isn't going to send us any further + * WINDOW_ADJUSTs to permit us to send pending + * stuff. + */ + bufchain_clear(&c->outbuffer); + bufchain_clear(&c->errbuffer); + + /* + * Send outgoing EOF. + */ + sshfwd_write_eof(&c->sc); + + /* + * Make sure we don't read any more from whatever + * our local data source is for this channel. + * (This will pick up on the changes made by + * sshfwd_write_eof.) + */ + ssh2_channel_check_throttle(c); + } + + /* + * Now process the actual close. + */ + if (!(c->closes & CLOSES_RCVD_CLOSE)) { + c->closes |= CLOSES_RCVD_CLOSE; + ssh2_channel_check_close(c); + } + + break; + } + + pq_pop(s->ppl.in_pq); + break; + + default: + return false; + } + } +} + +static void ssh2_handle_winadj_response(struct ssh2_channel *c, + PktIn *pktin, void *ctx) +{ + unsigned *sizep = ctx; + + /* + * Winadj responses should always be failures. However, at least + * one server ("boks_sshd") is known to return SUCCESS for channel + * requests it's never heard of, such as "winadj@putty". Raised + * with foxt.com as bug 090916-090424, but for the sake of a quiet + * life, we don't worry about what kind of response we got. + */ + + c->remlocwin += *sizep; + sfree(sizep); + /* + * winadj messages are only sent when the window is fully open, so + * if we get an ack of one, we know any pending unthrottle is + * complete. + */ + if (c->throttle_state == UNTHROTTLING) + c->throttle_state = UNTHROTTLED; +} + +static void ssh2_set_window(struct ssh2_channel *c, int newwin) +{ + struct ssh2_connection_state *s = c->connlayer; + + /* + * Never send WINDOW_ADJUST for a channel that the remote side has + * already sent EOF on; there's no point, since it won't be + * sending any more data anyway. Ditto if _we've_ already sent + * CLOSE. + */ + if (c->closes & (CLOSES_RCVD_EOF | CLOSES_SENT_CLOSE)) + return; + + /* + * If the client-side Channel is in an initial setup phase with a + * fixed window size, e.g. for an X11 channel when we're still + * waiting to see its initial auth and may yet hand it off to a + * downstream, don't send any WINDOW_ADJUST either. + */ + if (c->chan->initial_fixed_window_size) + return; + + /* + * If the remote end has a habit of ignoring maxpkt, limit the + * window so that it has no choice (assuming it doesn't ignore the + * window as well). + */ + if ((s->ppl.remote_bugs & BUG_SSH2_MAXPKT) && newwin > OUR_V2_MAXPKT) + newwin = OUR_V2_MAXPKT; + + /* + * Only send a WINDOW_ADJUST if there's significantly more window + * available than the other end thinks there is. This saves us + * sending a WINDOW_ADJUST for every character in a shell session. + * + * "Significant" is arbitrarily defined as half the window size. + */ + if (newwin / 2 >= c->locwindow) { + PktOut *pktout; + unsigned *up; + + /* + * In order to keep track of how much window the client + * actually has available, we'd like it to acknowledge each + * WINDOW_ADJUST. We can't do that directly, so we accompany + * it with a CHANNEL_REQUEST that has to be acknowledged. + * + * This is only necessary if we're opening the window wide. + * If we're not, then throughput is being constrained by + * something other than the maximum window size anyway. + */ + if (newwin == c->locmaxwin && + !(s->ppl.remote_bugs & BUG_CHOKES_ON_WINADJ)) { + up = snew(unsigned); + *up = newwin - c->locwindow; + pktout = ssh2_chanreq_init(c, "winadj@putty.projects.tartarus.org", + ssh2_handle_winadj_response, up); + pq_push(s->ppl.out_pq, pktout); + + if (c->throttle_state != UNTHROTTLED) + c->throttle_state = UNTHROTTLING; + } else { + /* Pretend the WINDOW_ADJUST was acked immediately. */ + c->remlocwin = newwin; + c->throttle_state = THROTTLED; + } + pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_WINDOW_ADJUST); + put_uint32(pktout, c->remoteid); + put_uint32(pktout, newwin - c->locwindow); + pq_push(s->ppl.out_pq, pktout); + c->locwindow = newwin; + } +} + +static PktIn *ssh2_connection_pop(struct ssh2_connection_state *s) +{ + ssh2_connection_filter_queue(s); + return pq_pop(s->ppl.in_pq); +} + +static void ssh2_connection_process_queue(PacketProtocolLayer *ppl) +{ + struct ssh2_connection_state *s = + container_of(ppl, struct ssh2_connection_state, ppl); + PktIn *pktin; + + if (ssh2_connection_filter_queue(s)) /* no matter why we were called */ + return; + + crBegin(s->crState); + + if (s->connshare) + share_activate(s->connshare, s->peer_verstring); + + /* + * Signal the seat that authentication is done, so that it can + * deploy spoofing defences. If it doesn't have any, deploy our + * own fallback one. + * + * We do this here rather than at the end of userauth, because we + * might not have gone through userauth at all (if we're a + * connection-sharing downstream). + */ + if (ssh2_connection_need_antispoof_prompt(s)) { + s->antispoof_prompt = new_prompts(); + s->antispoof_prompt->to_server = true; + s->antispoof_prompt->from_server = false; + s->antispoof_prompt->name = dupstr("Authentication successful"); +#ifndef MOD_PERSO + add_prompt( + s->antispoof_prompt, + dupstr("Access granted. Press Return to begin session. "), false); + s->antispoof_ret = seat_get_userpass_input( + s->ppl.seat, s->antispoof_prompt, NULL); +#endif + while (1) { + while (s->antispoof_ret < 0 && + bufchain_size(s->ppl.user_input) > 0) + s->antispoof_ret = seat_get_userpass_input( + s->ppl.seat, s->antispoof_prompt, s->ppl.user_input); + + if (s->antispoof_ret >= 0) + break; + + s->want_user_input = true; + crReturnV; + s->want_user_input = false; + } + free_prompts(s->antispoof_prompt); + s->antispoof_prompt = NULL; + } + + /* + * Enable port forwardings. + */ + portfwdmgr_config(s->portfwdmgr, s->conf); + s->portfwdmgr_configured = true; + + /* + * Create the main session channel, if any. + */ + s->mainchan = mainchan_new( + &s->ppl, &s->cl, s->conf, s->term_width, s->term_height, + s->ssh_is_simple, &s->mainchan_sc); + + /* + * Transfer data! + */ + + while (1) { + if ((pktin = ssh2_connection_pop(s)) != NULL) { + + /* + * _All_ the connection-layer packets we expect to + * receive are now handled by the dispatch table. + * Anything that reaches here must be bogus. + */ + + ssh_proto_error(s->ppl.ssh, "Received unexpected connection-layer " + "packet, type %d (%s)", pktin->type, + ssh2_pkt_type(s->ppl.bpp->pls->kctx, + s->ppl.bpp->pls->actx, + pktin->type)); + return; + } + crReturnV; + } + + crFinishV; +} + +static void ssh2_channel_check_close(struct ssh2_channel *c) +{ + struct ssh2_connection_state *s = c->connlayer; + PktOut *pktout; + + if (c->halfopen) { + /* + * If we've sent out our own CHANNEL_OPEN but not yet seen + * either OPEN_CONFIRMATION or OPEN_FAILURE in response, then + * it's too early to be sending close messages of any kind. + */ + return; + } + + if (chan_want_close(c->chan, (c->closes & CLOSES_SENT_EOF), + (c->closes & CLOSES_RCVD_EOF)) && + !c->chanreq_head && + !(c->closes & CLOSES_SENT_CLOSE)) { + /* + * We have both sent and received EOF (or the channel is a + * zombie), and we have no outstanding channel requests, which + * means the channel is in final wind-up. But we haven't sent + * CLOSE, so let's do so now. + */ + pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_CLOSE); + put_uint32(pktout, c->remoteid); + pq_push(s->ppl.out_pq, pktout); + c->closes |= CLOSES_SENT_EOF | CLOSES_SENT_CLOSE; + } + + if (!((CLOSES_SENT_CLOSE | CLOSES_RCVD_CLOSE) & ~c->closes)) { + assert(c->chanreq_head == NULL); + /* + * We have both sent and received CLOSE, which means we're + * completely done with the channel. + */ + ssh2_channel_destroy(c); + } +} + +static void ssh2_channel_try_eof(struct ssh2_channel *c) +{ + struct ssh2_connection_state *s = c->connlayer; + PktOut *pktout; + assert(c->pending_eof); /* precondition for calling us */ + if (c->halfopen) + return; /* can't close: not even opened yet */ + if (bufchain_size(&c->outbuffer) > 0 || bufchain_size(&c->errbuffer) > 0) + return; /* can't send EOF: pending outgoing data */ + + c->pending_eof = false; /* we're about to send it */ + + pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_EOF); + put_uint32(pktout, c->remoteid); + pq_push(s->ppl.out_pq, pktout); + c->closes |= CLOSES_SENT_EOF; + ssh2_channel_check_close(c); +} + +/* + * Attempt to send data on an SSH-2 channel. + */ +static size_t ssh2_try_send(struct ssh2_channel *c) +{ + struct ssh2_connection_state *s = c->connlayer; + PktOut *pktout; + size_t bufsize; + + if (!c->halfopen) { + while (c->remwindow > 0 && + (bufchain_size(&c->outbuffer) > 0 || + bufchain_size(&c->errbuffer) > 0)) { + bufchain *buf = (bufchain_size(&c->errbuffer) > 0 ? + &c->errbuffer : &c->outbuffer); + + ptrlen data = bufchain_prefix(buf); + if (data.len > c->remwindow) + data.len = c->remwindow; + if (data.len > c->remmaxpkt) + data.len = c->remmaxpkt; + if (buf == &c->errbuffer) { + pktout = ssh_bpp_new_pktout( + s->ppl.bpp, SSH2_MSG_CHANNEL_EXTENDED_DATA); + put_uint32(pktout, c->remoteid); + put_uint32(pktout, SSH2_EXTENDED_DATA_STDERR); + } else { + pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_DATA); + put_uint32(pktout, c->remoteid); + } + put_stringpl(pktout, data); + pq_push(s->ppl.out_pq, pktout); + bufchain_consume(buf, data.len); + c->remwindow -= data.len; + } + } + + /* + * After having sent as much data as we can, return the amount + * still buffered. + */ + bufsize = bufchain_size(&c->outbuffer) + bufchain_size(&c->errbuffer); + + /* + * And if there's no data pending but we need to send an EOF, send + * it. + */ + if (!bufsize && c->pending_eof) + ssh2_channel_try_eof(c); + + return bufsize; +} + +static void ssh2_try_send_and_unthrottle(struct ssh2_channel *c) +{ + int bufsize; + if (c->closes & CLOSES_SENT_EOF) + return; /* don't send on channels we've EOFed */ + bufsize = ssh2_try_send(c); + if (bufsize == 0) { + c->throttled_by_backlog = false; + ssh2_channel_check_throttle(c); + } +} + +static void ssh2_channel_check_throttle(struct ssh2_channel *c) +{ + /* + * We don't want this channel to read further input if this + * particular channel has a backed-up SSH window, or if the + * outgoing side of the whole SSH connection is currently + * throttled, or if this channel already has an outgoing EOF + * either sent or pending. + */ + chan_set_input_wanted(c->chan, + !c->throttled_by_backlog && + !c->connlayer->all_channels_throttled && + !c->pending_eof && + !(c->closes & CLOSES_SENT_EOF)); +} + +/* + * Close any local socket and free any local resources associated with + * a channel. This converts the channel into a zombie. + */ +static void ssh2_channel_close_local(struct ssh2_channel *c, + const char *reason) +{ + struct ssh2_connection_state *s = c->connlayer; + PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */ + char *msg = NULL; + + if (c->sharectx) + return; + + msg = chan_log_close_msg(c->chan); + + if (msg) + ppl_logevent("%s%s%s", msg, reason ? " " : "", reason ? reason : ""); + + sfree(msg); + + chan_free(c->chan); + c->chan = zombiechan_new(); +} + +static void ssh2_check_termination_callback(void *vctx) +{ + struct ssh2_connection_state *s = (struct ssh2_connection_state *)vctx; + ssh2_check_termination(s); +} + +static void ssh2_channel_destroy(struct ssh2_channel *c) +{ + struct ssh2_connection_state *s = c->connlayer; + + assert(c->chanreq_head == NULL); + + ssh2_channel_close_local(c, NULL); + del234(s->channels, c); + ssh2_channel_free(c); + + /* + * If that was the last channel left open, we might need to + * terminate. But we'll be a bit cautious, by doing that in a + * toplevel callback, just in case anything on the current call + * stack objects to this entire PPL being freed. + */ + queue_toplevel_callback(ssh2_check_termination_callback, s); +} + +static void ssh2_check_termination(struct ssh2_connection_state *s) +{ + /* + * Decide whether we should terminate the SSH connection now. + * Called after a channel or a downstream goes away. The general + * policy is that we terminate when none of either is left. + */ + + if (s->persistent) + return; /* persistent mode: never proactively terminate */ + + if (count234(s->channels) == 0 && + !(s->connshare && share_ndownstreams(s->connshare) > 0)) { + /* + * We used to send SSH_MSG_DISCONNECT here, because I'd + * believed that _every_ conforming SSH-2 connection had to + * end with a disconnect being sent by at least one side; + * apparently I was wrong and it's perfectly OK to + * unceremoniously slam the connection shut when you're done, + * and indeed OpenSSH feels this is more polite than sending a + * DISCONNECT. So now we don't. + */ + ssh_user_close(s->ppl.ssh, "All channels closed"); + return; + } +} + +/* + * Set up most of a new ssh2_channel. Nulls out sharectx, but leaves + * chan untouched (since it will sometimes have been filled in before + * calling this). + */ +void ssh2_channel_init(struct ssh2_channel *c) +{ + struct ssh2_connection_state *s = c->connlayer; + c->closes = 0; + c->pending_eof = false; + c->throttling_conn = false; + c->throttled_by_backlog = false; + c->sharectx = NULL; + c->locwindow = c->locmaxwin = c->remlocwin = + s->ssh_is_simple ? OUR_V2_BIGWIN : OUR_V2_WINSIZE; + c->chanreq_head = NULL; + c->throttle_state = UNTHROTTLED; + bufchain_init(&c->outbuffer); + bufchain_init(&c->errbuffer); + c->sc.vt = &ssh2channel_vtable; + c->sc.cl = &s->cl; + c->localid = alloc_channel_id(s->channels, struct ssh2_channel); + add234(s->channels, c); +} + +/* + * Construct the common parts of a CHANNEL_OPEN. + */ +PktOut *ssh2_chanopen_init(struct ssh2_channel *c, const char *type) +{ + struct ssh2_connection_state *s = c->connlayer; + PktOut *pktout; + + pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_OPEN); + put_stringz(pktout, type); + put_uint32(pktout, c->localid); + put_uint32(pktout, c->locwindow); /* our window size */ + put_uint32(pktout, OUR_V2_MAXPKT); /* our max pkt size */ + return pktout; +} + +/* + * Construct the common parts of a CHANNEL_REQUEST. If handler is not + * NULL then a reply will be requested and the handler will be called + * when it arrives. The returned packet is ready to have any + * request-specific data added and be sent. Note that if a handler is + * provided, it's essential that the request actually be sent. + * + * The handler will usually be passed the response packet in pktin. If + * pktin is NULL, this means that no reply will ever be forthcoming + * (e.g. because the entire connection is being destroyed, or because + * the server initiated channel closure before we saw the response) + * and the handler should free any storage it's holding. + */ +PktOut *ssh2_chanreq_init(struct ssh2_channel *c, const char *type, + cr_handler_fn_t handler, void *ctx) +{ + struct ssh2_connection_state *s = c->connlayer; + PktOut *pktout; + + assert(!(c->closes & (CLOSES_SENT_CLOSE | CLOSES_RCVD_CLOSE))); + pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_REQUEST); + put_uint32(pktout, c->remoteid); + put_stringz(pktout, type); + put_bool(pktout, handler != NULL); + if (handler != NULL) { + struct outstanding_channel_request *ocr = + snew(struct outstanding_channel_request); + + ocr->handler = handler; + ocr->ctx = ctx; + ocr->next = NULL; + if (!c->chanreq_head) + c->chanreq_head = ocr; + else + c->chanreq_tail->next = ocr; + c->chanreq_tail = ocr; + } + return pktout; +} + +static Conf *ssh2channel_get_conf(SshChannel *sc) +{ + struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); + struct ssh2_connection_state *s = c->connlayer; + return s->conf; +} + +static void ssh2channel_write_eof(SshChannel *sc) +{ + struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); + + if (c->closes & CLOSES_SENT_EOF) + return; + + c->pending_eof = true; + ssh2_channel_try_eof(c); +} + +static void ssh2channel_initiate_close(SshChannel *sc, const char *err) +{ + struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); + char *reason; + + reason = err ? dupprintf("due to local error: %s", err) : NULL; + ssh2_channel_close_local(c, reason); + sfree(reason); + c->pending_eof = false; /* this will confuse a zombie channel */ + + ssh2_channel_check_close(c); +} + +static void ssh2channel_unthrottle(SshChannel *sc, size_t bufsize) +{ + struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); + struct ssh2_connection_state *s = c->connlayer; + size_t buflimit; + + buflimit = s->ssh_is_simple ? 0 : c->locmaxwin; + if (bufsize < buflimit) + ssh2_set_window(c, buflimit - bufsize); + + if (c->throttling_conn && bufsize <= buflimit) { + c->throttling_conn = false; + ssh_throttle_conn(s->ppl.ssh, -1); + } +} + +static size_t ssh2channel_write( + SshChannel *sc, bool is_stderr, const void *buf, size_t len) +{ + struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); + assert(!(c->closes & CLOSES_SENT_EOF)); + bufchain_add(is_stderr ? &c->errbuffer : &c->outbuffer, buf, len); + return ssh2_try_send(c); +} + +static void ssh2channel_x11_sharing_handover( + SshChannel *sc, ssh_sharing_connstate *share_cs, share_channel *share_chan, + const char *peer_addr, int peer_port, int endian, + int protomajor, int protominor, const void *initial_data, int initial_len) +{ + struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); + /* + * This function is called when we've just discovered that an X + * forwarding channel on which we'd been handling the initial auth + * ourselves turns out to be destined for a connection-sharing + * downstream. So we turn the channel into a sharing one, meaning + * that we completely stop tracking windows and buffering data and + * just pass more or less unmodified SSH messages back and forth. + */ + c->sharectx = share_cs; + share_setup_x11_channel(share_cs, share_chan, + c->localid, c->remoteid, c->remwindow, + c->remmaxpkt, c->locwindow, + peer_addr, peer_port, endian, + protomajor, protominor, + initial_data, initial_len); + chan_free(c->chan); + c->chan = NULL; +} + +static void ssh2channel_window_override_removed(SshChannel *sc) +{ + struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); + struct ssh2_connection_state *s = c->connlayer; + + /* + * This function is called when a client-side Channel has just + * stopped requiring an initial fixed-size window. + */ + assert(!c->chan->initial_fixed_window_size); + ssh2_set_window(c, s->ssh_is_simple ? OUR_V2_BIGWIN : OUR_V2_WINSIZE); +} + +static void ssh2channel_hint_channel_is_simple(SshChannel *sc) +{ + struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); + struct ssh2_connection_state *s = c->connlayer; + + PktOut *pktout = ssh2_chanreq_init( + c, "simple@putty.projects.tartarus.org", NULL, NULL); + pq_push(s->ppl.out_pq, pktout); +} + +static SshChannel *ssh2_lportfwd_open( + ConnectionLayer *cl, const char *hostname, int port, + const char *description, const SocketPeerInfo *pi, Channel *chan) +{ + struct ssh2_connection_state *s = + container_of(cl, struct ssh2_connection_state, cl); + struct ssh2_channel *c = snew(struct ssh2_channel); + PktOut *pktout; + + c->connlayer = s; + ssh2_channel_init(c); + c->halfopen = true; + c->chan = chan; + + pktout = ssh2_portfwd_chanopen(s, c, hostname, port, description, pi); + pq_push(s->ppl.out_pq, pktout); + + return &c->sc; +} + +static void ssh2_sharing_globreq_response( + struct ssh2_connection_state *s, PktIn *pktin, void *ctx) +{ + ssh_sharing_connstate *cs = (ssh_sharing_connstate *)ctx; + share_got_pkt_from_server(cs, pktin->type, + BinarySource_UPCAST(pktin)->data, + BinarySource_UPCAST(pktin)->len); +} + +static void ssh2_sharing_queue_global_request( + ConnectionLayer *cl, ssh_sharing_connstate *cs) +{ + struct ssh2_connection_state *s = + container_of(cl, struct ssh2_connection_state, cl); + ssh2_queue_global_request_handler(s, ssh2_sharing_globreq_response, cs); +} + +static void ssh2_sharing_no_more_downstreams(ConnectionLayer *cl) +{ + struct ssh2_connection_state *s = + container_of(cl, struct ssh2_connection_state, cl); + queue_toplevel_callback(ssh2_check_termination_callback, s); +} + +static struct X11FakeAuth *ssh2_add_x11_display( + ConnectionLayer *cl, int authtype, struct X11Display *disp) +{ + struct ssh2_connection_state *s = + container_of(cl, struct ssh2_connection_state, cl); + struct X11FakeAuth *auth = x11_invent_fake_auth(s->x11authtree, authtype); + auth->disp = disp; + return auth; +} + +static struct X11FakeAuth *ssh2_add_sharing_x11_display( + ConnectionLayer *cl, int authtype, ssh_sharing_connstate *share_cs, + share_channel *share_chan) +{ + struct ssh2_connection_state *s = + container_of(cl, struct ssh2_connection_state, cl); + struct X11FakeAuth *auth; + + /* + * Make up a new set of fake X11 auth data, and add it to the tree + * of currently valid ones with an indication of the sharing + * context that it's relevant to. + */ + auth = x11_invent_fake_auth(s->x11authtree, authtype); + auth->share_cs = share_cs; + auth->share_chan = share_chan; + + return auth; +} + +static void ssh2_remove_sharing_x11_display( + ConnectionLayer *cl, struct X11FakeAuth *auth) +{ + struct ssh2_connection_state *s = + container_of(cl, struct ssh2_connection_state, cl); + del234(s->x11authtree, auth); + x11_free_fake_auth(auth); +} + +static unsigned ssh2_alloc_sharing_channel( + ConnectionLayer *cl, ssh_sharing_connstate *connstate) +{ + struct ssh2_connection_state *s = + container_of(cl, struct ssh2_connection_state, cl); + struct ssh2_channel *c = snew(struct ssh2_channel); + + c->connlayer = s; + ssh2_channel_init(c); + c->chan = NULL; + c->sharectx = connstate; + return c->localid; +} + +static void ssh2_delete_sharing_channel(ConnectionLayer *cl, unsigned localid) +{ + struct ssh2_connection_state *s = + container_of(cl, struct ssh2_connection_state, cl); + struct ssh2_channel *c = find234(s->channels, &localid, ssh2_channelfind); + if (c) + ssh2_channel_destroy(c); +} + +static void ssh2_send_packet_from_downstream( + ConnectionLayer *cl, unsigned id, int type, + const void *data, int datalen, const char *additional_log_text) +{ + struct ssh2_connection_state *s = + container_of(cl, struct ssh2_connection_state, cl); + PktOut *pkt = ssh_bpp_new_pktout(s->ppl.bpp, type); + pkt->downstream_id = id; + pkt->additional_log_text = additional_log_text; + put_data(pkt, data, datalen); + pq_push(s->ppl.out_pq, pkt); +} + +static bool ssh2_agent_forwarding_permitted(ConnectionLayer *cl) +{ + struct ssh2_connection_state *s = + container_of(cl, struct ssh2_connection_state, cl); + return conf_get_bool(s->conf, CONF_agentfwd) && agent_exists(); +} + +static bool ssh2_connection_get_specials( + PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx) +{ + struct ssh2_connection_state *s = + container_of(ppl, struct ssh2_connection_state, ppl); + bool toret = false; + + if (s->mainchan) { + mainchan_get_specials(s->mainchan, add_special, ctx); + toret = true; + } + + /* + * Don't bother offering IGNORE if we've decided the remote + * won't cope with it, since we wouldn't bother sending it if + * asked anyway. + */ + if (!(s->ppl.remote_bugs & BUG_CHOKES_ON_SSH2_IGNORE)) { + if (toret) + add_special(ctx, NULL, SS_SEP, 0); + + add_special(ctx, "IGNORE message", SS_NOP, 0); + toret = true; + } + + return toret; +} + +static void ssh2_connection_special_cmd(PacketProtocolLayer *ppl, + SessionSpecialCode code, int arg) +{ + struct ssh2_connection_state *s = + container_of(ppl, struct ssh2_connection_state, ppl); + PktOut *pktout; + + if (code == SS_PING || code == SS_NOP) { + if (!(s->ppl.remote_bugs & BUG_CHOKES_ON_SSH2_IGNORE)) { + pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_IGNORE); + put_stringz(pktout, ""); + pq_push(s->ppl.out_pq, pktout); + } + } else if (s->mainchan) { + mainchan_special_cmd(s->mainchan, code, arg); + } +} + +static void ssh2_terminal_size(ConnectionLayer *cl, int width, int height) +{ + struct ssh2_connection_state *s = + container_of(cl, struct ssh2_connection_state, cl); + + s->term_width = width; + s->term_height = height; + if (s->mainchan) + mainchan_terminal_size(s->mainchan, width, height); +} + +static void ssh2_stdout_unthrottle(ConnectionLayer *cl, size_t bufsize) +{ + struct ssh2_connection_state *s = + container_of(cl, struct ssh2_connection_state, cl); + + if (s->mainchan) + sshfwd_unthrottle(s->mainchan_sc, bufsize); +} + +static size_t ssh2_stdin_backlog(ConnectionLayer *cl) +{ + struct ssh2_connection_state *s = + container_of(cl, struct ssh2_connection_state, cl); + struct ssh2_channel *c; + + if (!s->mainchan) + return 0; + c = container_of(s->mainchan_sc, struct ssh2_channel, sc); + return s->mainchan ? + bufchain_size(&c->outbuffer) + bufchain_size(&c->errbuffer) : 0; +} + +static void ssh2_throttle_all_channels(ConnectionLayer *cl, bool throttled) +{ + struct ssh2_connection_state *s = + container_of(cl, struct ssh2_connection_state, cl); + struct ssh2_channel *c; + int i; + + s->all_channels_throttled = throttled; + + for (i = 0; NULL != (c = index234(s->channels, i)); i++) + if (!c->sharectx) + ssh2_channel_check_throttle(c); +} + +static bool ssh2_ldisc_option(ConnectionLayer *cl, int option) +{ + struct ssh2_connection_state *s = + container_of(cl, struct ssh2_connection_state, cl); + + return s->ldisc_opts[option]; +} + +static void ssh2_set_ldisc_option(ConnectionLayer *cl, int option, bool value) +{ + struct ssh2_connection_state *s = + container_of(cl, struct ssh2_connection_state, cl); + + s->ldisc_opts[option] = value; +} + +static void ssh2_enable_x_fwd(ConnectionLayer *cl) +{ + struct ssh2_connection_state *s = + container_of(cl, struct ssh2_connection_state, cl); + + s->X11_fwd_enabled = true; +} + +static void ssh2_enable_agent_fwd(ConnectionLayer *cl) +{ + struct ssh2_connection_state *s = + container_of(cl, struct ssh2_connection_state, cl); + + s->agent_fwd_enabled = true; +} + +static void ssh2_set_wants_user_input(ConnectionLayer *cl, bool wanted) +{ + struct ssh2_connection_state *s = + container_of(cl, struct ssh2_connection_state, cl); + + s->want_user_input = wanted; +} + +static bool ssh2_connection_want_user_input(PacketProtocolLayer *ppl) +{ + struct ssh2_connection_state *s = + container_of(ppl, struct ssh2_connection_state, ppl); + return s->want_user_input; +} + +static void ssh2_connection_got_user_input(PacketProtocolLayer *ppl) +{ + struct ssh2_connection_state *s = + container_of(ppl, struct ssh2_connection_state, ppl); + + while (s->mainchan && bufchain_size(s->ppl.user_input) > 0) { + /* + * Add user input to the main channel's buffer. + */ + ptrlen data = bufchain_prefix(s->ppl.user_input); + sshfwd_write(s->mainchan_sc, data.ptr, data.len); + bufchain_consume(s->ppl.user_input, data.len); + } +} + +static void ssh2_connection_reconfigure(PacketProtocolLayer *ppl, Conf *conf) +{ + struct ssh2_connection_state *s = + container_of(ppl, struct ssh2_connection_state, ppl); + + conf_free(s->conf); + s->conf = conf_copy(conf); + + if (s->portfwdmgr_configured) + portfwdmgr_config(s->portfwdmgr, s->conf); +} diff --git a/0.72_My_PuTTY/ssh2connection.h b/0.73_My_PuTTY/ssh2connection.h similarity index 100% rename from 0.72_My_PuTTY/ssh2connection.h rename to 0.73_My_PuTTY/ssh2connection.h diff --git a/0.72_My_PuTTY/ssh2kex-client.c b/0.73_My_PuTTY/ssh2kex-client.c similarity index 100% rename from 0.72_My_PuTTY/ssh2kex-client.c rename to 0.73_My_PuTTY/ssh2kex-client.c diff --git a/0.72_My_PuTTY/ssh2kex-server.c b/0.73_My_PuTTY/ssh2kex-server.c similarity index 100% rename from 0.72_My_PuTTY/ssh2kex-server.c rename to 0.73_My_PuTTY/ssh2kex-server.c diff --git a/0.72_My_PuTTY/ssh2transhk.c b/0.73_My_PuTTY/ssh2transhk.c similarity index 100% rename from 0.72_My_PuTTY/ssh2transhk.c rename to 0.73_My_PuTTY/ssh2transhk.c diff --git a/0.72_My_PuTTY/ssh2transport.c b/0.73_My_PuTTY/ssh2transport.c similarity index 97% rename from 0.72_My_PuTTY/ssh2transport.c rename to 0.73_My_PuTTY/ssh2transport.c index 3b45708..3813af2 100644 --- a/0.72_My_PuTTY/ssh2transport.c +++ b/0.73_My_PuTTY/ssh2transport.c @@ -314,8 +314,7 @@ static struct kexinit_algorithm *ssh2_kexinit_addalg(struct kexinit_algorithm list[i].name = name; return &list[i]; } - assert(!"No space in KEXINIT list"); - return NULL; + unreachable("Should never run out of space in KEXINIT list"); } bool ssh2_common_filter_queue(PacketProtocolLayer *ppl) diff --git a/0.72_My_PuTTY/ssh2transport.h b/0.73_My_PuTTY/ssh2transport.h similarity index 100% rename from 0.72_My_PuTTY/ssh2transport.h rename to 0.73_My_PuTTY/ssh2transport.h diff --git a/0.72_My_PuTTY/ssh2userauth-server.c b/0.73_My_PuTTY/ssh2userauth-server.c similarity index 100% rename from 0.72_My_PuTTY/ssh2userauth-server.c rename to 0.73_My_PuTTY/ssh2userauth-server.c diff --git a/0.72_My_PuTTY/ssh2userauth.c b/0.73_My_PuTTY/ssh2userauth.c similarity index 99% rename from 0.72_My_PuTTY/ssh2userauth.c rename to 0.73_My_PuTTY/ssh2userauth.c index 0c5fd6c..3a1cc83 100644 --- a/0.72_My_PuTTY/ssh2userauth.c +++ b/0.73_My_PuTTY/ssh2userauth.c @@ -18,7 +18,7 @@ #define BANNER_LIMIT 131072 -#ifdef PERSOPORT +#ifdef MOD_PERSO #include "kitty.h" void SetSSHConnected( int flag ); char bufpass[1024]=""; @@ -247,7 +247,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl) container_of(ppl, struct ssh2_userauth_state, ppl); PktIn *pktin; -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT is_backend_connected = 1 ; #endif @@ -289,7 +289,7 @@ is_backend_connected = 1 ; ppl_logevent("Key file contains public key only"); s->privatekey_encrypted = ssh2_userkey_encrypted(s->keyfile, NULL); -#ifdef WINCRYPTPORT +#ifdef MOD_WINCRYPT #ifdef USE_CAPI if(s->publickey_comment && 0 == strncmp("cert://", s->publickey_comment, 7)) { sfree(s->keyfile->path); @@ -452,7 +452,7 @@ is_backend_connected = 1 ; sfree(s->locally_allocated_username); /* for change_username */ s->username = s->locally_allocated_username = dupstr(s->cur_prompt->prompts[0]->result); -#ifdef PERSOPORT +#ifdef MOD_PERSO SetUsernameInConfig( (char*)s->username ) ; #endif free_prompts(s->cur_prompt); @@ -623,14 +623,14 @@ is_backend_connected = 1 ; ppl_logevent("Keyboard-interactive authentication " "failed"); ppl_printf("Access denied\r\n"); -#ifdef PERSOPORT +#ifdef MOD_PERSO SetPasswordInConfig("") ; #endif } else { assert(s->type == AUTH_TYPE_PASSWORD); ppl_logevent("Password authentication failed"); ppl_printf("Access denied\r\n"); -#ifdef PERSOPORT +#ifdef MOD_PERSO SetPasswordInConfig("") ; #endif @@ -885,7 +885,7 @@ is_backend_connected = 1 ; dupprintf("Passphrase for key \"%s\": ", s->publickey_comment), false); -#ifdef PERSOPORT +#ifdef MOD_PERSO //SetSSHConnected(1); if( strlen(ManagePassPhrase(NULL))>0 ) { char *p = ManagePassPhrase(NULL) ; @@ -1343,9 +1343,14 @@ is_backend_connected = 1 ; sb = strbuf_new(); if (name.len) { - stripctrl_retarget(s->ki_scc, BinarySink_UPCAST(sb)); + if (s->ki_scc) { + stripctrl_retarget(s->ki_scc, + BinarySink_UPCAST(sb)); put_datapl(s->ki_scc, name); stripctrl_retarget(s->ki_scc, NULL); + } else { + put_datapl(sb, name); + } s->cur_prompt->name_reqd = true; } else { @@ -1357,9 +1362,14 @@ is_backend_connected = 1 ; sb = strbuf_new(); if (inst.len) { - stripctrl_retarget(s->ki_scc, BinarySink_UPCAST(sb)); + if (s->ki_scc) { + stripctrl_retarget(s->ki_scc, + BinarySink_UPCAST(sb)); put_datapl(s->ki_scc, inst); stripctrl_retarget(s->ki_scc, NULL); + } else { + put_datapl(sb, inst); + } s->cur_prompt->instr_reqd = true; } else { @@ -1372,7 +1382,7 @@ is_backend_connected = 1 ; * Our prompts_t is fully constructed now. Get the * user's response(s). */ -#ifdef PERSOPORT +#ifdef MOD_PERSO if( IsPasswordInConf() ) { GetPasswordInConfig(bufpass) ; while( ((bufpass[strlen(bufpass)-1]=='n')&&(bufpass[strlen(bufpass)-2]=='\\')) || ((bufpass[strlen(bufpass)-1]=='r')&&(bufpass[strlen(bufpass)-2]=='\\')) ) { @@ -1402,7 +1412,7 @@ is_backend_connected = 1 ; #endif s->userpass_ret = seat_get_userpass_input( s->ppl.seat, s->cur_prompt, NULL); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( !IsPasswordInConf() ) #endif while (1) { @@ -1438,7 +1448,7 @@ is_backend_connected = 1 ; s->ppl.bpp, SSH2_MSG_USERAUTH_INFO_RESPONSE); put_uint32(s->pktout, s->num_prompts); for (uint32_t i = 0; i < s->num_prompts; i++) { -#ifdef PERSOPORT +#ifdef MOD_PERSO ppl_logevent("Sent password"); if(!GetUserPassSSHNoSave()) { if(s!=NULL) @@ -1500,7 +1510,7 @@ is_backend_connected = 1 ; s->userpass_ret = seat_get_userpass_input( s->ppl.seat, s->cur_prompt, NULL); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( !IsPasswordInConf() ) #endif while (1) { @@ -1552,7 +1562,7 @@ is_backend_connected = 1 ; put_stringz(s->pktout, s->successor_layer->vt->name); put_stringz(s->pktout, "password"); put_bool(s->pktout, false); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( IsPasswordInConf() ) { GetPasswordInConfig(bufpass); while( ((bufpass[strlen(bufpass)-1]=='n')&&(bufpass[strlen(bufpass)-2]=='\\')) || ((bufpass[strlen(bufpass)-1]=='r')&&(bufpass[strlen(bufpass)-2]=='\\')) ) { @@ -1587,7 +1597,7 @@ is_backend_connected = 1 ; * request. */ crMaybeWaitUntilV((pktin = ssh2_userauth_pop(s)) != NULL); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( !GetUserPassSSHNoSave() ) { if( strlen(bufpass)>0 ) { SetPasswordInConfig( bufpass ) ; @@ -1781,7 +1791,7 @@ is_backend_connected = 1 ; } userauth_success: -#ifdef PERSOPORT +#ifdef MOD_PERSO SetSSHConnected(1) ; #endif /* diff --git a/0.72_My_PuTTY/sshaes.c b/0.73_My_PuTTY/sshaes.c similarity index 100% rename from 0.72_My_PuTTY/sshaes.c rename to 0.73_My_PuTTY/sshaes.c diff --git a/0.72_My_PuTTY/ssharcf.c b/0.73_My_PuTTY/ssharcf.c similarity index 100% rename from 0.72_My_PuTTY/ssharcf.c rename to 0.73_My_PuTTY/ssharcf.c diff --git a/0.72_My_PuTTY/sshauxcrypt.c b/0.73_My_PuTTY/sshauxcrypt.c similarity index 100% rename from 0.72_My_PuTTY/sshauxcrypt.c rename to 0.73_My_PuTTY/sshauxcrypt.c diff --git a/0.72_My_PuTTY/sshbcrypt.c b/0.73_My_PuTTY/sshbcrypt.c similarity index 100% rename from 0.72_My_PuTTY/sshbcrypt.c rename to 0.73_My_PuTTY/sshbcrypt.c diff --git a/0.72_My_PuTTY/sshblowf.c b/0.73_My_PuTTY/sshblowf.c similarity index 100% rename from 0.72_My_PuTTY/sshblowf.c rename to 0.73_My_PuTTY/sshblowf.c diff --git a/0.72_My_PuTTY/sshblowf.h b/0.73_My_PuTTY/sshblowf.h similarity index 100% rename from 0.72_My_PuTTY/sshblowf.h rename to 0.73_My_PuTTY/sshblowf.h diff --git a/0.72_My_PuTTY/sshbpp.h b/0.73_My_PuTTY/sshbpp.h similarity index 100% rename from 0.72_My_PuTTY/sshbpp.h rename to 0.73_My_PuTTY/sshbpp.h diff --git a/0.72_My_PuTTY/sshccp.c b/0.73_My_PuTTY/sshccp.c similarity index 100% rename from 0.72_My_PuTTY/sshccp.c rename to 0.73_My_PuTTY/sshccp.c diff --git a/0.72_My_PuTTY/sshchan.h b/0.73_My_PuTTY/sshchan.h similarity index 100% rename from 0.72_My_PuTTY/sshchan.h rename to 0.73_My_PuTTY/sshchan.h diff --git a/0.72_My_PuTTY/sshcommon.c b/0.73_My_PuTTY/sshcommon.c similarity index 99% rename from 0.72_My_PuTTY/sshcommon.c rename to 0.73_My_PuTTY/sshcommon.c index 39f2a65..2607384 100644 --- a/0.72_My_PuTTY/sshcommon.c +++ b/0.73_My_PuTTY/sshcommon.c @@ -980,7 +980,7 @@ bool ssh1_common_filter_queue(PacketProtocolLayer *ppl) ssh_remote_error(ppl->ssh, "Remote side sent disconnect message:\n\"%.*s\"", PTRLEN_PRINTF(msg)); - pq_pop(ppl->in_pq); + /* don't try to pop the queue, because we've been freed! */ return true; /* indicate that we've been freed */ case SSH1_MSG_DEBUG: diff --git a/0.72_My_PuTTY/sshcr.h b/0.73_My_PuTTY/sshcr.h similarity index 100% rename from 0.72_My_PuTTY/sshcr.h rename to 0.73_My_PuTTY/sshcr.h diff --git a/0.72_My_PuTTY/sshcrc.c b/0.73_My_PuTTY/sshcrc.c similarity index 100% rename from 0.72_My_PuTTY/sshcrc.c rename to 0.73_My_PuTTY/sshcrc.c diff --git a/0.72_My_PuTTY/sshcrcda.c b/0.73_My_PuTTY/sshcrcda.c similarity index 100% rename from 0.72_My_PuTTY/sshcrcda.c rename to 0.73_My_PuTTY/sshcrcda.c diff --git a/0.72_My_PuTTY/sshdes.c b/0.73_My_PuTTY/sshdes.c similarity index 100% rename from 0.72_My_PuTTY/sshdes.c rename to 0.73_My_PuTTY/sshdes.c diff --git a/0.72_My_PuTTY/sshdh.c b/0.73_My_PuTTY/sshdh.c similarity index 100% rename from 0.72_My_PuTTY/sshdh.c rename to 0.73_My_PuTTY/sshdh.c diff --git a/0.72_My_PuTTY/sshdss.c b/0.73_My_PuTTY/sshdss.c similarity index 100% rename from 0.72_My_PuTTY/sshdss.c rename to 0.73_My_PuTTY/sshdss.c diff --git a/0.72_My_PuTTY/sshdssg.c b/0.73_My_PuTTY/sshdssg.c similarity index 100% rename from 0.72_My_PuTTY/sshdssg.c rename to 0.73_My_PuTTY/sshdssg.c diff --git a/0.72_My_PuTTY/sshecc.c b/0.73_My_PuTTY/sshecc.c similarity index 100% rename from 0.72_My_PuTTY/sshecc.c rename to 0.73_My_PuTTY/sshecc.c diff --git a/0.72_My_PuTTY/sshecdsag.c b/0.73_My_PuTTY/sshecdsag.c similarity index 100% rename from 0.72_My_PuTTY/sshecdsag.c rename to 0.73_My_PuTTY/sshecdsag.c diff --git a/0.72_My_PuTTY/sshgss.h b/0.73_My_PuTTY/sshgss.h similarity index 100% rename from 0.72_My_PuTTY/sshgss.h rename to 0.73_My_PuTTY/sshgss.h diff --git a/0.72_My_PuTTY/sshgssc.c b/0.73_My_PuTTY/sshgssc.c similarity index 100% rename from 0.72_My_PuTTY/sshgssc.c rename to 0.73_My_PuTTY/sshgssc.c diff --git a/0.72_My_PuTTY/sshgssc.h b/0.73_My_PuTTY/sshgssc.h similarity index 100% rename from 0.72_My_PuTTY/sshgssc.h rename to 0.73_My_PuTTY/sshgssc.h diff --git a/0.72_My_PuTTY/sshhmac.c b/0.73_My_PuTTY/sshhmac.c similarity index 100% rename from 0.72_My_PuTTY/sshhmac.c rename to 0.73_My_PuTTY/sshhmac.c diff --git a/0.72_My_PuTTY/sshmac.c b/0.73_My_PuTTY/sshmac.c similarity index 100% rename from 0.72_My_PuTTY/sshmac.c rename to 0.73_My_PuTTY/sshmac.c diff --git a/0.72_My_PuTTY/sshmd5.c b/0.73_My_PuTTY/sshmd5.c similarity index 100% rename from 0.72_My_PuTTY/sshmd5.c rename to 0.73_My_PuTTY/sshmd5.c diff --git a/0.72_My_PuTTY/sshnogss.c b/0.73_My_PuTTY/sshnogss.c similarity index 100% rename from 0.72_My_PuTTY/sshnogss.c rename to 0.73_My_PuTTY/sshnogss.c diff --git a/0.72_My_PuTTY/sshppl.h b/0.73_My_PuTTY/sshppl.h similarity index 100% rename from 0.72_My_PuTTY/sshppl.h rename to 0.73_My_PuTTY/sshppl.h diff --git a/0.72_My_PuTTY/sshprime.c b/0.73_My_PuTTY/sshprime.c similarity index 100% rename from 0.72_My_PuTTY/sshprime.c rename to 0.73_My_PuTTY/sshprime.c diff --git a/0.72_My_PuTTY/sshprng.c b/0.73_My_PuTTY/sshprng.c similarity index 100% rename from 0.72_My_PuTTY/sshprng.c rename to 0.73_My_PuTTY/sshprng.c diff --git a/0.72_My_PuTTY/sshpubk.c b/0.73_My_PuTTY/sshpubk.c similarity index 99% rename from 0.72_My_PuTTY/sshpubk.c rename to 0.73_My_PuTTY/sshpubk.c index 9e3f278..60b1784 100644 --- a/0.72_My_PuTTY/sshpubk.c +++ b/0.73_My_PuTTY/sshpubk.c @@ -622,7 +622,7 @@ ssh2_userkey *ssh2_load_userkey( int passlen = passphrase ? strlen(passphrase) : 0; const char *error = NULL; -#ifdef WINCRYPTPORT +#ifdef MOD_WINCRYPT #ifdef USE_CAPI if(0 == strncmp("cert://", filename->path, 7)) { alg = find_pubkey_alg("ssh-rsa"); @@ -1087,7 +1087,7 @@ bool ssh2_userkey_loadpub(const Filename *filename, char **algorithm, int type, i; const char *error = NULL; char *comment = NULL; -#ifdef WINCRYPTPORT +#ifdef MOD_WINCRYPT #ifdef USE_CAPI struct RSAKey *key; if(0 == strncmp("cert://", filename->path, 7)) { @@ -1588,7 +1588,7 @@ static int key_type_fp(FILE *fp) i = fread(buf, 1, sizeof(buf)-1, fp); rewind(fp); -#ifdef WINCRYPTPORT +#ifdef MOD_WINCRYPT #ifdef USE_CAPI /* if(0 == strncmp("cert://", filename->path, 7)) { @@ -1635,7 +1635,7 @@ int key_type(const Filename *filename) FILE *fp; int ret; -#ifdef WINCRYPTPORT +#ifdef MOD_WINCRYPT #ifdef USE_CAPI if(0 == strncmp("cert://", filename->path, 7)) { return SSH_KEYTYPE_SSH2; diff --git a/0.72_My_PuTTY/sshrand.c b/0.73_My_PuTTY/sshrand.c similarity index 98% rename from 0.72_My_PuTTY/sshrand.c rename to 0.73_My_PuTTY/sshrand.c index 7e737f6..dcbf64a 100644 --- a/0.72_My_PuTTY/sshrand.c +++ b/0.73_My_PuTTY/sshrand.c @@ -123,7 +123,7 @@ void random_clear(void) void random_unref(void) { -#ifndef RECONNECTPORT +#ifndef MOD_RECONNECT assert(random_active > 0); #endif if (--random_active == 0) @@ -146,7 +146,7 @@ void random_get_savedata(void **data, int *len) size_t random_seed_bits(void) { -#ifndef RECONNECTPORT +#ifndef MOD_RECONNECT assert(random_active > 0); #endif return prng_seed_bits(global_prng); diff --git a/0.72_My_PuTTY/sshrsa.c b/0.73_My_PuTTY/sshrsa.c similarity index 99% rename from 0.72_My_PuTTY/sshrsa.c rename to 0.73_My_PuTTY/sshrsa.c index 1055731..ae7ff1c 100644 --- a/0.72_My_PuTTY/sshrsa.c +++ b/0.73_My_PuTTY/sshrsa.c @@ -11,7 +11,7 @@ #include "mpint.h" #include "misc.h" -#ifdef WINCRYPTPORT +#ifdef MOD_WINCRYPT #ifdef USE_CAPI #ifdef _WINDOWS #include "wincrypto.h" @@ -304,7 +304,7 @@ bool rsa_verify(RSAKey *key) mp_int *n, *ed, *pm1, *qm1; unsigned ok = 1; -#ifdef WINCRYPTPORT +#ifdef MOD_WINCRYPT #ifdef USE_CAPI #ifdef _WINDOWS if(capi_is_capikey(key)) { diff --git a/0.72_My_PuTTY/sshrsag.c b/0.73_My_PuTTY/sshrsag.c similarity index 100% rename from 0.72_My_PuTTY/sshrsag.c rename to 0.73_My_PuTTY/sshrsag.c diff --git a/0.72_My_PuTTY/sshserver.c b/0.73_My_PuTTY/sshserver.c similarity index 100% rename from 0.72_My_PuTTY/sshserver.c rename to 0.73_My_PuTTY/sshserver.c diff --git a/0.72_My_PuTTY/sshserver.h b/0.73_My_PuTTY/sshserver.h similarity index 100% rename from 0.72_My_PuTTY/sshserver.h rename to 0.73_My_PuTTY/sshserver.h diff --git a/0.72_My_PuTTY/sshsh256.c b/0.73_My_PuTTY/sshsh256.c similarity index 100% rename from 0.72_My_PuTTY/sshsh256.c rename to 0.73_My_PuTTY/sshsh256.c diff --git a/0.72_My_PuTTY/sshsh512.c b/0.73_My_PuTTY/sshsh512.c similarity index 100% rename from 0.72_My_PuTTY/sshsh512.c rename to 0.73_My_PuTTY/sshsh512.c diff --git a/0.72_My_PuTTY/sshsha.c b/0.73_My_PuTTY/sshsha.c similarity index 100% rename from 0.72_My_PuTTY/sshsha.c rename to 0.73_My_PuTTY/sshsha.c diff --git a/0.72_My_PuTTY/sshshare.c b/0.73_My_PuTTY/sshshare.c similarity index 100% rename from 0.72_My_PuTTY/sshshare.c rename to 0.73_My_PuTTY/sshshare.c diff --git a/0.72_My_PuTTY/sshsignals.h b/0.73_My_PuTTY/sshsignals.h similarity index 100% rename from 0.72_My_PuTTY/sshsignals.h rename to 0.73_My_PuTTY/sshsignals.h diff --git a/0.72_My_PuTTY/sshttymodes.h b/0.73_My_PuTTY/sshttymodes.h similarity index 100% rename from 0.72_My_PuTTY/sshttymodes.h rename to 0.73_My_PuTTY/sshttymodes.h diff --git a/0.72_My_PuTTY/sshverstring.c b/0.73_My_PuTTY/sshverstring.c similarity index 99% rename from 0.72_My_PuTTY/sshverstring.c rename to 0.73_My_PuTTY/sshverstring.c index 22eff87..638a9ef 100644 --- a/0.72_My_PuTTY/sshverstring.c +++ b/0.73_My_PuTTY/sshverstring.c @@ -161,7 +161,7 @@ static void ssh_verstring_send(struct ssh_verstring_state *s) /* * Construct our outgoing version string. */ -#ifdef PERSOPORT +#ifdef MOD_PERSO s->our_vstring = dupprintf( "%.*s%s-%s", (int)s->prefix_wanted.len, (const char *)s->prefix_wanted.ptr, diff --git a/0.72_My_PuTTY/sshzlib.c b/0.73_My_PuTTY/sshzlib.c similarity index 100% rename from 0.72_My_PuTTY/sshzlib.c rename to 0.73_My_PuTTY/sshzlib.c diff --git a/0.72_My_PuTTY/storage.h b/0.73_My_PuTTY/storage.h similarity index 100% rename from 0.72_My_PuTTY/storage.h rename to 0.73_My_PuTTY/storage.h diff --git a/0.72_My_PuTTY/stripctrl.c b/0.73_My_PuTTY/stripctrl.c similarity index 100% rename from 0.72_My_PuTTY/stripctrl.c rename to 0.73_My_PuTTY/stripctrl.c diff --git a/0.72_My_PuTTY/telnet.c b/0.73_My_PuTTY/telnet.c similarity index 100% rename from 0.72_My_PuTTY/telnet.c rename to 0.73_My_PuTTY/telnet.c diff --git a/0.72_My_PuTTY/terminal.c b/0.73_My_PuTTY/terminal.c similarity index 99% rename from 0.72_My_PuTTY/terminal.c rename to 0.73_My_PuTTY/terminal.c index b52ed8a..575cb06 100644 --- a/0.72_My_PuTTY/terminal.c +++ b/0.73_My_PuTTY/terminal.c @@ -13,20 +13,20 @@ #include "putty.h" #include "terminal.h" -#ifdef PERSOPORT +#ifdef MOD_PERSO int get_param( const char * val ) ; int frontend_is_utf8(void *frontend) ; int GetPuttyFlag(void) ; int GetHyperlinkFlag(void) ; #endif -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK /* * HACK: PuttyTray / Nutty */ #include "urlhack.h" void wintw_clip_write(TermWin *tw, int clipboard, wchar_t *data, int *attr,truecolour *truecolour, int len, bool must_deselect); #endif -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM int xyz_ReceiveData(Terminal *term, const u_char *buffer, int len); int GetZModemFlag(void) ; #endif @@ -825,7 +825,7 @@ static void readrle(BinarySource *bs, termline *ldata, int count = hdr + 1; while (count--) { -#ifndef PERSOPORT +#ifndef MOD_PERSO assert(n < ldata->cols); #endif readliteral(bs, ldata->chars + n, ldata, &state); @@ -1128,7 +1128,7 @@ static termline *lineptr(Terminal *term, int y, int lineno, int screen) treeindex = y; } else { int altlines = 0; -#ifndef PERSOPORT +#ifndef MOD_PERSO assert(!screen); #endif if (term->erase_to_scrollback && @@ -1519,7 +1519,8 @@ void term_copy_stuff_from_conf(Terminal *term) term->utf8linedraw = conf_get_bool(term->conf, CONF_utf8linedraw); term->rect_select = conf_get_bool(term->conf, CONF_rect_select); term->remote_qtitle_action = conf_get_int(term->conf, CONF_remote_qtitle_action); -#ifdef PERSOPORT +#ifdef MOD_PERSO + term->enter_sends_crlf = conf_get_int(term->conf, CONF_enter_sends_crlf); term->rxvt_homeend = conf_get_int(term->conf, CONF_rxvt_homeend); #else term->rxvt_homeend = conf_get_bool(term->conf, CONF_rxvt_homeend); @@ -1632,7 +1633,7 @@ void term_reconfig(Terminal *term, Conf *conf) term->sco_acs = term->alt_sco_acs = 0; term->utf = false; } -#ifdef PRINTCLIPPORT +#ifdef MOD_PRINTCLIP if (!conf_get_str(term->conf, CONF_printer) || conf_get_int(term->conf, CONF_printclip) ) { #else if (!conf_get_str(term->conf, CONF_printer)) { @@ -1760,7 +1761,7 @@ Terminal *term_init(Conf *myconf, struct unicode_data *ucsdata, TermWin *win) term->bidi_cache_size = 0; term->pre_bidi_cache = term->post_bidi_cache = NULL; -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK /* * HACK: PuttyTray / Nutty */ @@ -1788,7 +1789,7 @@ Terminal *term_init(Conf *myconf, struct unicode_data *ucsdata, TermWin *win) term->last_graphic_char = 0; term->trusted = true; -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM term->xyz_transfering = 0; term->xyz_Internals = NULL; #endif @@ -2065,7 +2066,7 @@ static int find_last_nonempty_line(Terminal * term, tree234 * screen) for (i = count234(screen) - 1; i >= 0; i--) { termline *line = index234(screen, i); int j; -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK assert(term->erase_char.cc_next == 0); #endif for (j = 0; j < line->cols; j++) @@ -2309,7 +2310,7 @@ static void scroll(Terminal *term, int topline, int botline, term->disptop--; } resizeline(term, line, term->cols); -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK assert(term->erase_char.cc_next == 0); #endif clear_line(term, line); @@ -2534,7 +2535,7 @@ static void erase_lots(Terminal *term, else ldata->lattr = LATTR_NORM; } else { -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK assert(term->erase_char.cc_next == 0); #endif copy_termchar(ldata, start.x, &term->erase_char); @@ -2623,7 +2624,7 @@ static void insch(Terminal *term, int n) move_termchar(ldata, ldata->chars + term->curs.x + j + n, ldata->chars + term->curs.x + j); -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK assert(term->erase_char.cc_next == 0); #endif while (n--) @@ -2806,7 +2807,7 @@ static void do_osc(Terminal *term) } } -#ifdef PRINTCLIPPORT +#ifdef MOD_PRINTCLIP /* * Windows clipboard support * Diomidis Spinellis, June 2003 @@ -2867,7 +2868,7 @@ static void do_osc(Terminal *term) static void term_print_setup(Terminal *term, char *printer) { bufchain_clear(&term->printer_buf); -#ifdef PRINTCLIPPORT +#ifdef MOD_PRINTCLIP if ( conf_get_int(term->conf,CONF_printclip) ) clipboard_init(); else @@ -2881,7 +2882,7 @@ static void term_print_flush(Terminal *term) ptrlen data = bufchain_prefix(&term->printer_buf); if (data.len > size-5) data.len = size-5; -#ifdef PRINTCLIPPORT +#ifdef MOD_PRINTCLIP if ( conf_get_int(term->conf,CONF_printclip) ) clipboard_data(data.ptr, data.len); else @@ -2906,7 +2907,7 @@ static void term_print_finish(Terminal *term) bufchain_consume(&term->printer_buf, size); break; } else { -#ifdef PRINTCLIPPORT +#ifdef MOD_PRINTCLIP if ( conf_get_int(term->conf,CONF_printclip) ) clipboard_data(&c, 1); else @@ -2915,7 +2916,7 @@ static void term_print_finish(Terminal *term) bufchain_consume(&term->printer_buf, 1); } } -#ifdef PRINTCLIPPORT +#ifdef MOD_PRINTCLIP if ( conf_get_int(term->conf,CONF_printclip) ) clipboard_copy(); else @@ -3293,24 +3294,14 @@ unsigned long term_translate( return t; } -#ifdef ACSPORT - /* Are we in the nasty ACS mode? Note: no sco in utf mode. */ - /* Actually we can allow it for broken apps (like ncurses) */ - } else if ( (!in_utf(term) || (conf_get_bool(term->conf,CONF_acs_in_utf) && c < 0x100)) && term->sco_acs && -#else } else if (term->sco_acs && -#endif (c!='\033' && c!='\012' && c!='\015' && c!='\b')) { /* Are we in the nasty ACS mode? Note: no sco in utf mode. */ if (term->sco_acs == 2) c |= 0x80; return c | CSET_SCOACS; -#ifdef ACSPORT - } else if (!in_utf(term) || (conf_get_bool(term->conf,CONF_acs_in_utf) && c < 0x100)) { -#else } else { -#endif switch (term->cset_attr[term->cset]) { /* * Linedraw characters are different from 'ESC ( B' @@ -3467,7 +3458,7 @@ static void term_out(Terminal *term) if (!term->no_dbackspace) { check_boundary(term, term->curs.x, term->curs.y); check_boundary(term, term->curs.x+1, term->curs.y); -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK assert(term->erase_char.cc_next == 0); #endif copy_termchar(scrlineptr(term->curs.y), @@ -4091,7 +4082,7 @@ static void term_out(Terminal *term) char *printer; if (term->esc_nargs != 1) break; if (term->esc_args[0] == 5 && -#ifdef PRINTCLIPPORT +#ifdef MOD_PRINTCLIP ((printer = conf_get_str(term->conf, CONF_printer))[0] || conf_get_int(term->conf,CONF_printclip)) ) { #else @@ -4211,7 +4202,7 @@ static void term_out(Terminal *term) compatibility(OTHER); term->curr_attr |= ATTR_DIM; break; -#ifdef PERSOPORT +#ifdef MOD_PERSO case 3: /* enable italics */ compatibility(ANSI); term->curr_attr |= ATTR_ITALIC; @@ -5496,7 +5487,7 @@ static void do_paint(Terminal *term) wchar_t *ch; size_t chlen; termchar *newline; -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK /* * HACK: PuttyTray / Nutty * Hyperlink stuff: Find visible hyperlinks @@ -5689,7 +5680,7 @@ static void do_paint(Terminal *term) } if (j < term->cols-1 && d[1].chr == UCSWIDE) tattr |= ATTR_WIDE; -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK /* * HACK: PuttyTray / Nutty * Hyperlink stuff: Underline link regions if user has configured us so @@ -5743,7 +5734,7 @@ static void do_paint(Terminal *term) posPlt(scrpos, term->selend)); } else selected = false; -#ifdef TUTTYPORT +#ifdef MOD_TUTTY tattr = (tattr ^ rv ^ (selected ? ATTR_SELECTED : 0)); #else tattr = (tattr ^ rv @@ -6039,7 +6030,7 @@ void term_paint(Terminal *term, void term_scroll(Terminal *term, int rel, int where) { int sbtop = -sblines(term); -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK /* * HACK: PuttyTray / Nutty */ @@ -6110,7 +6101,7 @@ static void clip_addchar(clip_workbuf *b, wchar_t chr, int attr, truecolour tc) b->bufpos++; } -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK static void clipme(Terminal *term, pos top, pos bottom, bool rect, bool desel, const int *clipboards, int n_clipboards , void (*output)(TermWin *, int, wchar_t *, int *, truecolour *, int, bool)) @@ -6323,7 +6314,7 @@ void term_copyall(Terminal *term, const int *clipboards, int n_clipboards) top.x = 0; bottom.y = find_last_nonempty_line(term, screen); bottom.x = term->cols; -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK clipme(term, top, bottom, false, true, clipboards, n_clipboards, wintw_clip_write); #else clipme(term, top, bottom, false, true, clipboards, n_clipboards); @@ -6734,7 +6725,7 @@ void term_do_paste(Terminal *term, const wchar_t *data, int len) queue_toplevel_callback(term_paste_callback, term); } -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK void urlhack_launch_url_helper( void *frontend, wchar_t * data, int *attr, int len, int must_deselect) { //urlhack_launch_url( (!conf_get_int(term->conf, CONF_url_defbrowser) ? conf_get_filename(term->conf, CONF_url_browser)->path : NULL), (const char *)data) ; //urlhack_launch_url( (!conf_get_int(term->conf, CONF_url_defbrowser) ? conf_get_filename(term->conf, CONF_url_browser)->path : NULL), (const char *)data,0) ; @@ -6797,7 +6788,7 @@ void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked, } selpoint.x = x; -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK if( !GetPuttyFlag() && GetHyperlinkFlag() ) unlineptr(ldata); #else unlineptr(ldata); @@ -6853,7 +6844,7 @@ void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked, return; } else switch (a) { case MA_DRAG: -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK if( !GetPuttyFlag() && GetHyperlinkFlag() ) { if (term->xterm_mouse == 1) {// HACK: ADDED FOR hyperlink stuff unlineptr(ldata); @@ -6877,9 +6868,9 @@ void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked, term->mouse_is_down = 0; break; case MA_CLICK: -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK if( !GetPuttyFlag() && GetHyperlinkFlag() ) { -#ifdef PUTTYXPORT +#ifdef MOD_PUTTYX if (term->mouse_is_down == braw && braw != MBT_WHEEL_UP && braw != MBT_WHEEL_DOWN) {// HACK: ADDED FOR hyperlink stuff // MORE HACKING (@unphased: allow sequences of mouse wheel up and mouse wheel down to pass through) #else if (term->mouse_is_down == braw) {// HACK: ADDED FOR hyperlink stuff @@ -6889,7 +6880,7 @@ void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked, } } else { -#ifdef PUTTYXPORT +#ifdef MOD_PUTTYX if (term->mouse_is_down == braw && braw != MBT_WHEEL_UP && braw != MBT_WHEEL_DOWN) // MORE HACKING (@unphased: allow sequences of mouse wheel up and mouse wheel down to pass through) #else if (term->mouse_is_down == braw) @@ -6897,7 +6888,7 @@ void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked, return; } #else -#ifdef PUTTYXPORT +#ifdef MOD_PUTTYX if (term->mouse_is_down == braw && braw != MBT_WHEEL_UP && braw != MBT_WHEEL_DOWN) // MORE HACKING (@unphased: allow sequences of mouse wheel up and mouse wheel down to pass through) #else if (term->mouse_is_down == braw) @@ -6927,7 +6918,7 @@ void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked, if (len > 0) ldisc_send(term->ldisc, abuf, len, false); } -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK if( !GetPuttyFlag() && GetHyperlinkFlag() ) { unlineptr(ldata); // HACK: ADDED FOR hyperlink stuff } @@ -6954,7 +6945,7 @@ void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked, term->seltype = default_seltype; term->selanchor = selpoint; term->selmode = SM_CHAR; -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK /* * HACK: PuttyTray / Nutty * Hyperlink stuff: Check whether the click coordinates are inside link @@ -7031,7 +7022,7 @@ void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked, */ return; } -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK if( !GetPuttyFlag() && GetHyperlinkFlag() ) { if (term->selstate == ABOUT_TO && poseq(term->selanchor, selpoint)) { // HACK: ADDED FOR HYPERLINK STUFF unlineptr(ldata); @@ -7118,7 +7109,7 @@ void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked, clipme(term, term->selstart, term->selend, (term->seltype == RECTANGULAR), false, term->mouse_select_clipboards, -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK term->n_mouse_select_clipboards,wintw_clip_write); #else term->n_mouse_select_clipboards); @@ -7145,7 +7136,7 @@ void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked, term_update(term); } -#ifdef KEYMAPPINGPORT +#ifdef MOD_KEYMAPPING int format_arrow_key(char *buf, Terminal *term, int xkey, int modifier, bool alt) #else int format_arrow_key(char *buf, Terminal *term, int xkey, bool ctrl) @@ -7172,7 +7163,7 @@ int format_arrow_key(char *buf, Terminal *term, int xkey, bool ctrl) if (!term->app_keypad_keys) app_flg = 0; #endif -#ifdef KEYMAPPINGPORT +#ifdef MOD_KEYMAPPING if( !GetPuttyFlag() ) { if (modifier == 3 && alt == 1) p += sprintf((char *) p, "\x1B[1;8%c", xkey); /*Control+Alt-Shift */ @@ -7296,14 +7287,14 @@ int format_small_keypad_key(char *buf, Terminal *term, SmallKeypadKey key) } else { p += sprintf(p, "\x1B[%c", codes[code-1]); } -#ifdef PERSOPORT +#ifdef MOD_PERSO } else if ((code == 1 || code == 4) && (conf_get_int(conf, CONF_rxvt_homeend) == 1) ) { #else } else if ((code == 1 || code == 4) && term->rxvt_homeend) { #endif p += sprintf(p, code == 1 ? "\x1B[H" : "\x1BOw"); } else { -#ifdef PERSOPORT +#ifdef MOD_PERSO if ((code == 1 || code == 4) && conf_get_int(conf, CONF_rxvt_homeend) == 2) { // urxvt @@ -7492,7 +7483,7 @@ static void term_added_data(Terminal *term) size_t term_data(Terminal *term, bool is_stderr, const void *data, size_t len) { -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM if ( GetZModemFlag() && term->xyz_transfering && !is_stderr) { return xyz_ReceiveData(term, (const u_char *) data, len) ; } else @@ -7501,13 +7492,13 @@ size_t term_data(Terminal *term, bool is_stderr, const void *data, size_t len) bufchain_add(&term->inbuf, data, len); term_added_data(term); -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK /* * HACK: PuttyTray / Nutty */ if( !GetPuttyFlag() && GetHyperlinkFlag() ) term->url_update = TRUE; #endif -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM } #endif /* diff --git a/0.72_My_PuTTY/terminal.h b/0.73_My_PuTTY/terminal.h similarity index 99% rename from 0.72_My_PuTTY/terminal.h rename to 0.73_My_PuTTY/terminal.h index 524c4a1..43e39de 100644 --- a/0.72_My_PuTTY/terminal.h +++ b/0.73_My_PuTTY/terminal.h @@ -238,7 +238,7 @@ struct terminal_tag { unsigned long last_graphic_char; -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM int xyz_transfering; struct zModemInternals *xyz_Internals; #endif @@ -333,7 +333,8 @@ struct terminal_tag { bool utf8linedraw; bool rect_select; int remote_qtitle_action; -#ifdef PERSOPORT +#ifdef MOD_PERSO + int enter_sends_crlf; int rxvt_homeend; #else bool rxvt_homeend; @@ -350,7 +351,7 @@ struct terminal_tag { int mouse_select_clipboards[N_CLIPBOARDS]; int n_mouse_select_clipboards; int mouse_paste_clipboard; -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK /* * HACK: PuttyTray / Nutty */ diff --git a/0.72_My_PuTTY/testback.c b/0.73_My_PuTTY/testback.c similarity index 100% rename from 0.72_My_PuTTY/testback.c rename to 0.73_My_PuTTY/testback.c diff --git a/0.72_My_PuTTY/testcrypt.c b/0.73_My_PuTTY/testcrypt.c similarity index 100% rename from 0.72_My_PuTTY/testcrypt.c rename to 0.73_My_PuTTY/testcrypt.c diff --git a/0.72_My_PuTTY/testcrypt.h b/0.73_My_PuTTY/testcrypt.h similarity index 100% rename from 0.72_My_PuTTY/testcrypt.h rename to 0.73_My_PuTTY/testcrypt.h diff --git a/0.72_My_PuTTY/testsc.c b/0.73_My_PuTTY/testsc.c similarity index 100% rename from 0.72_My_PuTTY/testsc.c rename to 0.73_My_PuTTY/testsc.c diff --git a/0.72_My_PuTTY/testzlib.c b/0.73_My_PuTTY/testzlib.c similarity index 100% rename from 0.72_My_PuTTY/testzlib.c rename to 0.73_My_PuTTY/testzlib.c diff --git a/0.72_My_PuTTY/time.c b/0.73_My_PuTTY/time.c similarity index 100% rename from 0.72_My_PuTTY/time.c rename to 0.73_My_PuTTY/time.c diff --git a/0.72_My_PuTTY/timing.c b/0.73_My_PuTTY/timing.c similarity index 100% rename from 0.72_My_PuTTY/timing.c rename to 0.73_My_PuTTY/timing.c diff --git a/0.72_My_PuTTY/tree234.c b/0.73_My_PuTTY/tree234.c similarity index 100% rename from 0.72_My_PuTTY/tree234.c rename to 0.73_My_PuTTY/tree234.c diff --git a/0.72_My_PuTTY/tree234.h b/0.73_My_PuTTY/tree234.h similarity index 100% rename from 0.72_My_PuTTY/tree234.h rename to 0.73_My_PuTTY/tree234.h diff --git a/0.72_My_PuTTY/unix/unix.h b/0.73_My_PuTTY/unix/unix.h similarity index 100% rename from 0.72_My_PuTTY/unix/unix.h rename to 0.73_My_PuTTY/unix/unix.h diff --git a/0.72_My_PuTTY/utils.c b/0.73_My_PuTTY/utils.c similarity index 100% rename from 0.72_My_PuTTY/utils.c rename to 0.73_My_PuTTY/utils.c diff --git a/0.72_My_PuTTY/version.c b/0.73_My_PuTTY/version.c similarity index 98% rename from 0.72_My_PuTTY/version.c rename to 0.73_My_PuTTY/version.c index 031e74d..600be94 100644 --- a/0.72_My_PuTTY/version.c +++ b/0.73_My_PuTTY/version.c @@ -14,7 +14,7 @@ #include "version.h" -#ifdef PERSOPORT +#ifdef MOD_PERSO #include #include const char ver[] = "Custom build" ; diff --git a/0.72_My_PuTTY/version.h b/0.73_My_PuTTY/version.h similarity index 100% rename from 0.72_My_PuTTY/version.h rename to 0.73_My_PuTTY/version.h diff --git a/0.72_My_PuTTY/wcwidth.c b/0.73_My_PuTTY/wcwidth.c similarity index 100% rename from 0.72_My_PuTTY/wcwidth.c rename to 0.73_My_PuTTY/wcwidth.c diff --git a/0.72_My_PuTTY/wildcard.c b/0.73_My_PuTTY/wildcard.c similarity index 100% rename from 0.72_My_PuTTY/wildcard.c rename to 0.73_My_PuTTY/wildcard.c diff --git a/0.72_My_PuTTY/windows/MAKEFILE.MINGW b/0.73_My_PuTTY/windows/MAKEFILE.MINGW similarity index 97% rename from 0.72_My_PuTTY/windows/MAKEFILE.MINGW rename to 0.73_My_PuTTY/windows/MAKEFILE.MINGW index 2cdf16a..ee5e5ae 100644 --- a/0.72_My_PuTTY/windows/MAKEFILE.MINGW +++ b/0.73_My_PuTTY/windows/MAKEFILE.MINGW @@ -121,67 +121,69 @@ CFLAGS += -D_WIN32_IE=0x0500 #CFLAGS += -DWINVER=0x0500 -D_WIN32_WINDOWS=0x0410 -D_WIN32_WINNT=0x0500 ################################################################################ -# BEGIN PERSOPORT +# BEGIN MOD_PERSO # Ne pas oublier de commenter 2 lignes CFLAGS au-dessus (remplacé par en-dessous) ################################################################################ CFLAGS += -DWINVER=0x0501 -D_WIN32_WINDOWS=0x0410 -D_WIN32_WINNT=0x0501 -# -DPERSOPORT -DCYGTERMPORT -DIMAGEPORT -DRECONNECTPORT -DHYPERLINKPORT -DZMODEMPORT -DSTARTBUTTON -DLAUNCHERPORT -DSAVEDUMPPORT -DKEYMAPPINGPORT -DWINCRYPTPORT -DTUTTYPORT -DPORTKNOCKINGPORT -DPUTTYXPORT -DWTSPORT -DPRINTCLIPPORT -DRUTTYPORT -DADBPORT \ +# -DMOD_PERSO -DMOD_CYGTERM -DMOD_BACKGROUNDIMAGE -DMOD_RECONNECT -DMOD_HYPERLINK -DMOD_ZMODEM -DMOD_STARTBUTTON -DMOD_LAUNCHER -DMOD_SAVEDUMP -DMOD_KEYMAPPING -DMOD_WINCRYPT -DMOD_TUTTY -DMOD_PORTKNOCKING -DMOD_PUTTYX -DMOD_WTS -DMOD_PRINTCLIP -DMOD_RUTTY -DMOD_ADB \ -# Anciens flags: -# -DACSPORT \ # Flag special FDJ FDJFLAG = FDJ1 # Ajouter -g -ggdb a CFLAGS pour avoir plus de debug !!! -# Ajout du DEBIG +# Ajout du DEBUG # CFLAGS += -DDEBUG -RCFLAGS += -I ../../ -DPERSOPORT -D$(FDJFLAG) +RCFLAGS += -I ../../ -DMOD_PERSO -D$(FDJFLAG) CFLAGS += -DAUTO_WINSOCK -DCOVERITY -DNO_MULTIMON -DNO_HTMLHELP CFLAGS += -D$(FDJFLAG) -CFLAGS += -DPERSOPORT \ - -DSTARTBUTTON \ - -DSAVEDUMPPORT \ - -DDISABLEALTGRPORT \ - -DKEYMAPPINGPORT \ - -DPUTTYXPORT \ - -DPORTKNOCKINGPORT \ - -DHYPERLINKPORT \ - -DPRINTCLIPPORT \ - -DLAUNCHERPORT \ - -DRECONNECTPORT \ - -DWTSPORT \ - -DTUTTYPORT \ - -DRUTTYPORT \ - -DADBPORT \ +CFLAGS += -DMOD_PERSO \ + -DMOD_STARTBUTTON \ + -DMOD_SAVEDUMP \ + -DMOD_DISABLEALTGR \ + -DMOD_KEYMAPPING \ + -DMOD_PUTTYX \ + -DMOD_PORTKNOCKING \ + -DMOD_HYPERLINK \ + -DMOD_PRINTCLIP \ + -DMOD_LAUNCHER \ + -DMOD_RECONNECT \ + -DMOD_WTS \ + -DMOD_TUTTY \ + -DMOD_RUTTY \ + -DMOD_ADB \ + -DMOD_BACKGROUNDIMAGE \ -I.././ -I../../ \ -I../charset/ -I../windows/ -I../unix/ -I../mac/ \ -I../macosx \ -I../../base64 -I../../bcrypt -I../../md5 -I../../regex -I../../url -I../../wincrypt -I../../rutty -# -DCYGTERMPORT \ -# -DUSE_CAPI -DWINCRYPTPORT \ -# -DZMODEMPORT \ -# -DIMAGEPORT \ +# -DMOD_CYGTERM \ +# -DUSE_CAPI -DMOD_WINCRYPT \ +# -DMOD_ZMODEM \ # Autre flag a gérer -# Ajouter -DNO_PASSWORD \ pour compiler une version sans possibilité de sauvegarder le mot de passe -# Ajouter -DNO_TRANSPARENCY \ pour compiler une version desactivant la transparence -# Ajouter -DPORTABLE \ pour forcer le mode portable +# Ajouter -DMOD_NOPASSWORD \ pour compiler une version sans possibilité de sauvegarder le mot de passe +# Ajouter -DMOD_NOTRANSPARENCY \ pour compiler une version desactivant la transparence +# Ajouter -DMOD_NOHYPERLINK \ pour compiler une version desactivant la gestion des liens hyperlink +# Ajouter -DMOD_PORTABLE \ pour forcer le mode portable +# Autre flags +# MOD_INTEGRATED_AGENT: intègre l'agent directement +# MOD_INTEGRATED_KEYGEN: intègre le key generator directement CFLAGS_PLINK = -Wall -O2 -D_WINDOWS -DWIN32S_COMPAT \ - -DPERSOPORT -DPUTTYCYG -DRECONNECTPORT -DNO_RUTTYPORT \ + -DMOD_PERSO -DPUTTYCYG -DMOD_RECONNECT -DNO_MOD_RUTTY \ -D_NO_OLDNAMES -DNO_MULTIMON -DNO_HTMLHELP -I../. \ -I../charset -I../windows -I../unix -I../mac -I.\ -I../macosx \ -I../../base64 -I../../bcrypt -I../../md5 -I../../regex -I../../url ################################################################################ -# END PERSOPORT +# END MOD_PERSO ################################################################################ .SUFFIXES: @@ -842,7 +844,7 @@ putty.res.o: ../windows/putty.rc ../windows/rcstuff.h ../windows/winhelp.rc2 \ ../windows/puttycfg.ico ../windows/version.rc2 ../version.h \ ../licence.h \ ../../blocnote/notepad.rc - $(RC) $(RCFL) $(RCFLAGS) ../windows/putty.rc -o putty.res.o -DINTEGRATED_AGENT -DINTEGRATED_KEYGEN + $(RC) $(RCFL) $(RCFLAGS) ../windows/putty.rc -o putty.res.o -DMOD_INTEGRATED_AGENT -DMOD_INTEGRATED_KEYGEN puttygen.res.o: ../windows/puttygen.rc ../windows/rcstuff.h \ ../windows/winhelp.rc2 ../windows/puttygen.ico \ @@ -1577,7 +1579,7 @@ window.o: ../windows/window.c ../putty.h ../terminal.h ../storage.h \ -DBUILD_VERSION=`cat version_major.txt` \ -DBUILD_SUBVERSION=`cat version_minor.txt` \ -DMASTER_PASSWORD=`cat ../../masterpassword.txt` \ - -DINTEGRATED_AGENT -DINTEGRATED_KEYGEN + -DMOD_INTEGRATED_AGENT -DMOD_INTEGRATED_KEYGEN wingss.o: ../windows/wingss.c ../putty.h ../pgssapi.h ../sshgss.h \ ../sshgssc.h ../misc.h ../defs.h ../puttyps.h ../network.h \ @@ -1796,7 +1798,7 @@ xpmputty.o: ../unix/xpmputty.c FORCE: ################################################################################ -# BEGIN PERSOPORT +# BEGIN MOD_PERSO ################################################################################ cygcfg.o: ../../cygterm/cygcfg.c $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) -c ../../cygterm/cygcfg.c -I../../cygterm/ -I../../ @@ -1821,13 +1823,13 @@ pageant_integrated.o: ../pageant.c ../putty.h ../mpint.h ../ssh.h ../sshcr.h \ ../marshal.h ../sshsignals.h ../puttymem.h ../tree234.h \ ../sshttymodes.h ../windows/winstuff.h ../unix/unix.h \ ../windows/winhelp.h ../charset/charset.h - $(CC) $(COMPAT) $(CFLAGS) $(XFLAGS) -o pageant_integrated.o -c ../pageant.c -DINTEGRATED_AGENT + $(CC) $(COMPAT) $(CFLAGS) $(XFLAGS) -o pageant_integrated.o -c ../pageant.c -DMOD_INTEGRATED_AGENT settings_nohyperlink.o: ../settings.c ../putty.h ../storage.h ../puttyps.h ../network.h \ ../misc.h ../windows/winstuff.h \ ../unix/unix.h ../puttymem.h ../tree234.h \ ../windows/winhelp.h ../charset/charset.h - $(CC) $(COMPAT) $(CFLAGS) $(XFLAGS) -o settings_nohyperlink.o -c ../settings.c -DNO_HYPERLINK \ + $(CC) $(COMPAT) $(CFLAGS) $(XFLAGS) -o settings_nohyperlink.o -c ../settings.c -DMOD_NOHYPERLINK \ -DMASTER_PASSWORD=`cat ../../masterpassword.txt` winpgen_integrated.o: ../windows/winpgen.c ../putty.h ../ssh.h ../licence.h \ @@ -1835,14 +1837,14 @@ winpgen_integrated.o: ../windows/winpgen.c ../putty.h ../ssh.h ../licence.h \ ../misc.h ../marshal.h ../sshsignals.h ../puttymem.h \ ../tree234.h ../sshttymodes.h ../windows/winstuff.h \ ../unix/unix.h ../windows/winhelp.h ../charset/charset.h - $(CC) $(COMPAT) $(CFLAGS) $(XFLAGS) -o winpgen_integrated.o -c ../windows/winpgen.c -DINTEGRATED_KEYGEN + $(CC) $(COMPAT) $(CFLAGS) $(XFLAGS) -o winpgen_integrated.o -c ../windows/winpgen.c -DMOD_INTEGRATED_KEYGEN winpgnt_integrated.o: ../windows/winpgnt.c ../putty.h ../ssh.h ../misc.h ../tree234.h \ ../windows/winsecur.h ../pageant.h ../licence.h ../defs.h \ ../puttyps.h ../network.h ../marshal.h ../sshsignals.h \ ../puttymem.h ../sshttymodes.h ../windows/winstuff.h \ ../unix/unix.h ../windows/winhelp.h ../charset/charset.h - $(CC) $(COMPAT) $(CFLAGS) $(XFLAGS) -o winpgnt_integrated.o -c ../windows/winpgnt.c -DMASTER_PASSWORD=`cat ../../masterpassword.txt` -DINTEGRATED_AGENT + $(CC) $(COMPAT) $(CFLAGS) $(XFLAGS) -o winpgnt_integrated.o -c ../windows/winpgnt.c -DMASTER_PASSWORD=`cat ../../masterpassword.txt` -DMOD_INTEGRATED_AGENT adb.o: ../putty.h ../../adb/adb.c $(CC) $(COMPAT) $(CFLAGS) $(XFLAGS) -c ../../adb/adb.c -I../../adb -I../../ @@ -1856,7 +1858,7 @@ kitty.o: ../../kitty.c ../../kitty.h ../../kitty_savedump.c ../../kitty_launcher kitty_portable.o: ../../kitty.c ../../kitty.h ../../kitty_savedump.c ../../kitty_launcher.c ../../kitty_launcher.h $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) -o kitty_portable.o -c ../../kitty.c \ - -DPORTABLE \ + -DMOD_PORTABLE \ -DBUILD_TIME=`date +'"%d/%m/%Y-%H:%M:%S(%Z)"'` \ -DBUILD_VERSION=`cat version_major.txt` \ -DBUILD_SUBVERSION=`cat version_minor.txt` \ @@ -1864,7 +1866,7 @@ kitty_portable.o: ../../kitty.c ../../kitty.h ../../kitty_savedump.c ../../kitty kitty_nohyperlink.o: ../../kitty.c ../../kitty.h ../../kitty_savedump.c ../../kitty_launcher.c ../../kitty_launcher.h $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) -o kitty_nohyperlink.o -c ../../kitty.c \ - -DNO_HYPERLINK \ + -DMOD_NOHYPERLINK \ -DBUILD_TIME=`date +'"%d/%m/%Y-%H:%M:%S(%Z)"'` \ -DBUILD_VERSION=`cat version_major.txt` \ -DBUILD_SUBVERSION=`cat version_minor.txt` \ @@ -1874,22 +1876,22 @@ kitty_commun.o: ../../kitty_commun.c ../../kitty_commun.h $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) -c ../../kitty_commun.c kitty_commun_portable.o: ../../kitty_commun.c ../../kitty_commun.h - $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) -DPORTABLE -o kitty_commun_portable.o -c ../../kitty_commun.c + $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) -DMOD_PORTABLE -o kitty_commun_portable.o -c ../../kitty_commun.c kitty_crypt.o: ../../kitty_crypt.c ../../kitty_crypt.h $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) -DMASTER_PASSWORD=`cat ../../masterpassword.txt` -c ../../kitty_crypt.c kitty_image.o: ../../kitty_image.c - $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) -c ../../kitty_image.c -DNO + $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) -c ../../kitty_image.c kitty_iv.o: ../../kitty_iv.c ../../kitty_iv.h $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) -c ../../kitty_iv.c kitty_launcher.o: ../../kitty_launcher.c - $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) -c ../../kitty_launcher.c -DNO + $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) -c ../../kitty_launcher.c kitty_keygen.o: ../../kitty_keygen.c - $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) -c ../../kitty_keygen.c -DNO + $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) -c ../../kitty_keygen.c kitty_regex.o: ../../kitty_regex.c ../../kitty_regex.h $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) -c ../../kitty_regex.c @@ -1916,7 +1918,7 @@ urlhack.o: ../../url/urlhack.c ../../url/urlhack.h \ urlhack_nohyperlink.o: ../../url/urlhack.c ../../url/urlhack.h \ ../puttymem.h $(CC) $(COMPAT) $(CFLAGS) $(XFLAGS) -o urlhack_nohyperlink.o -c ../../url/urlhack.c \ - -DNO_HYPERLINK + -DMOD_NOHYPERLINK void.o: ../../void.c $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) -c ../../void.c @@ -1930,12 +1932,12 @@ window_notrans.o: ../windows/window.c ../putty.h ../terminal.h ../storage.h \ ../sshsignals.h ../windows/winstuff.h ../unix/unix.h \ ../puttymem.h ../windows/winhelp.h ../charset/charset.h $(CC) $(COMPAT) $(CFLAGS) $(XFLAGS) -o window_notrans.o -c ../windows/window.c \ - -DNO_TRANSPARENCY \ + -DMOD_NOTRANSPARENCY \ -DBUILD_TIME=`date +'"%d/%m/%Y-%H:%M:%S(%Z)"'` \ -DBUILD_VERSION=`cat version_major.txt` \ -DBUILD_SUBVERSION=`cat version_minor.txt` \ -DMASTER_PASSWORD=`cat ../../masterpassword.txt` \ - -DINTEGRATED_AGENT -DINTEGRATED_KEYGEN + -DMOD_INTEGRATED_AGENT -DMOD_INTEGRATED_KEYGEN window_nohyperlink.o: ../windows/window.c ../putty.h ../terminal.h ../storage.h \ ../windows/win_res.h ../puttyps.h ../network.h ../misc.h \ @@ -1944,7 +1946,7 @@ window_nohyperlink.o: ../windows/window.c ../putty.h ../terminal.h ../storage.h ../windows/winhelp.h ../charset/charset.h \ ../../kitty.c ../../kitty_launcher.c ../../kitty_image.c ../../kitty_crypt.c ../../kitty_savedump.c $(CC) $(COMPAT) $(CFLAGS) $(XFLAGS) -o window_nohyperlink.o -c ../windows/window.c \ - -DNO_HYPERLINK \ + -DMOD_NOHYPERLINK \ -DBUILD_TIME=`date +'"%d/%m/%Y-%H:%M:%S(%Z)"'` \ -DBUILD_VERSION=`cat version_major.txt` \ -DBUILD_SUBVERSION=`cat version_minor.txt` \ @@ -1957,11 +1959,11 @@ window_portable.o: ../windows/window.c ../putty.h ../terminal.h ../storage.h \ ../puttymem.h ../windows/winhelp.h ../charset/charset.h $(CC) $(COMPAT) $(CFLAGS) $(XFLAGS) -o window_portable.o -c ../windows/window.c \ -DBUILD_TIME=`date +'"%d/%m/%Y-%H:%M:%S(%Z)"'` \ - -DPORTABLE \ + -DMOD_PORTABLE \ -DBUILD_VERSION=`cat version_major.txt` \ -DBUILD_SUBVERSION=`cat version_minor.txt` \ -DMASTER_PASSWORD=`cat ../../masterpassword.txt` \ - -DINTEGRATED_AGENT -DINTEGRATED_KEYGEN + -DMOD_INTEGRATED_AGENT -DMOD_INTEGRATED_KEYGEN winpzmodem.o: ../../zmodem/winpzmodem.c $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) -c ../../zmodem/winpzmodem.c @@ -2135,13 +2137,13 @@ clean: # -DBUILD_VERSION=`cat version_major.txt` \ # -DBUILD_SUBVERSION=`cat version_minor.txt` \ # -DMASTER_PASSWORD=`cat ../../masterpassword.txt` \ -# -DINTEGRATED_AGENT à la compilation de putty.res.o -# -DINTEGRATED_AGENT à la compilation de window.o +# -DMOD_INTEGRATED_AGENT à la compilation de putty.res.o +# -DMOD_INTEGRATED_AGENT à la compilation de window.o # Ajouter winpgnt_integrated.o à la compilation de putty.exe # Ajouter pageant_integrated.o à la compilation de putty.exe # Ajouter ../../blocnote/notepad.rc à la compilation de putty.res.o -# Ajouter -DINTEGRATED_KEYGEN à la compiltation de putty.res.o -# Ajouter -DINTEGRATED_KEYGEN à la compiltation de window.o +# Ajouter -DMOD_INTEGRATED_KEYGEN à la compiltation de putty.res.o +# Ajouter -DMOD_INTEGRATED_KEYGEN à la compiltation de window.o # Ajouter winpgen_integrated.o à la compiltation de putty.exe # Ajouter import.o sshrsag.o sshdssg.o sshprime.o sshecdsag.o sshbcrypt.o à la compilation de putty.exe @@ -2149,6 +2151,6 @@ clean: # Pour putty_portable.exe copier putty.exe et remplacer window.o, kitty.o, kitty_commun.o par window_portable.o, kitty_portable.o, kitty_commun_portable.o ################################################################################ -# END PERSOPORT +# END MOD_PERSO ################################################################################ diff --git a/0.72_My_PuTTY/windows/pageant.ico b/0.73_My_PuTTY/windows/pageant.ico similarity index 100% rename from 0.72_My_PuTTY/windows/pageant.ico rename to 0.73_My_PuTTY/windows/pageant.ico diff --git a/0.72_My_PuTTY/windows/pageant.rc b/0.73_My_PuTTY/windows/pageant.rc similarity index 94% rename from 0.72_My_PuTTY/windows/pageant.rc rename to 0.73_My_PuTTY/windows/pageant.rc index 6d612df..44ee05d 100644 --- a/0.72_My_PuTTY/windows/pageant.rc +++ b/0.73_My_PuTTY/windows/pageant.rc @@ -4,7 +4,7 @@ #include "rcstuff.h" -#ifdef INTEGRATED_AGENT +#ifdef MOD_INTEGRATED_AGENT #define APPNAME_AGENT "Kageant" #define APPDESC_AGENT "KiTTY SSH authentication agent" #else @@ -14,7 +14,7 @@ #include "winhelp.rc2" -#ifdef INTEGRATED_AGENT +#ifdef MOD_INTEGRATED_AGENT 900 ICON "pageant.ico" 901 ICON "pageants.ico" #else @@ -24,7 +24,7 @@ 210 DIALOG DISCARDABLE 0, 0, 140, 60 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -#ifdef PERSOPORT +#ifdef MOD_PERSO CAPTION "Kageant: Enter Passphrase" #else CAPTION "Pageant: Enter Passphrase" @@ -40,7 +40,7 @@ END 211 DIALOG DISCARDABLE 0, 0, 330, 200 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -#ifdef PERSOPORT +#ifdef MOD_PERSO CAPTION "Kageant Key List" #else CAPTION "Pageant Key List" @@ -58,7 +58,7 @@ END /* Accelerators used: cl */ 213 DIALOG DISCARDABLE 140, 40, 270, 136 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -#ifdef PERSOPORT +#ifdef MOD_PERSO CAPTION "About Kageant" #else CAPTION "About Pageant" @@ -82,7 +82,7 @@ BEGIN EDITTEXT 1000, 10, 10, 306, 200, ES_READONLY | ES_MULTILINE | ES_LEFT, WS_EX_STATICEDGE END -#ifndef INTEGRATED_AGENT +#ifndef MOD_INTEGRATED_AGENT #include "version.rc2" #ifndef NO_MANIFESTS diff --git a/0.72_My_PuTTY/windows/pageants.ico b/0.73_My_PuTTY/windows/pageants.ico similarity index 100% rename from 0.72_My_PuTTY/windows/pageants.ico rename to 0.73_My_PuTTY/windows/pageants.ico diff --git a/0.72_My_PuTTY/windows/plink.rc b/0.73_My_PuTTY/windows/plink.rc similarity index 100% rename from 0.72_My_PuTTY/windows/plink.rc rename to 0.73_My_PuTTY/windows/plink.rc diff --git a/0.72_My_PuTTY/windows/pscp.ico b/0.73_My_PuTTY/windows/pscp.ico similarity index 100% rename from 0.72_My_PuTTY/windows/pscp.ico rename to 0.73_My_PuTTY/windows/pscp.ico diff --git a/0.72_My_PuTTY/windows/pscp.rc b/0.73_My_PuTTY/windows/pscp.rc similarity index 100% rename from 0.72_My_PuTTY/windows/pscp.rc rename to 0.73_My_PuTTY/windows/pscp.rc diff --git a/0.72_My_PuTTY/windows/psftp.rc b/0.73_My_PuTTY/windows/psftp.rc similarity index 100% rename from 0.72_My_PuTTY/windows/psftp.rc rename to 0.73_My_PuTTY/windows/psftp.rc diff --git a/0.72_My_PuTTY/windows/putty.ico b/0.73_My_PuTTY/windows/putty.ico similarity index 100% rename from 0.72_My_PuTTY/windows/putty.ico rename to 0.73_My_PuTTY/windows/putty.ico diff --git a/0.72_My_PuTTY/windows/putty.mft b/0.73_My_PuTTY/windows/putty.mft similarity index 100% rename from 0.72_My_PuTTY/windows/putty.mft rename to 0.73_My_PuTTY/windows/putty.mft diff --git a/0.72_My_PuTTY/windows/putty.rc b/0.73_My_PuTTY/windows/putty.rc similarity index 100% rename from 0.72_My_PuTTY/windows/putty.rc rename to 0.73_My_PuTTY/windows/putty.rc diff --git a/0.72_My_PuTTY/windows/puttycfg.ico b/0.73_My_PuTTY/windows/puttycfg.ico similarity index 100% rename from 0.72_My_PuTTY/windows/puttycfg.ico rename to 0.73_My_PuTTY/windows/puttycfg.ico diff --git a/0.72_My_PuTTY/windows/puttygen.ico b/0.73_My_PuTTY/windows/puttygen.ico similarity index 100% rename from 0.72_My_PuTTY/windows/puttygen.ico rename to 0.73_My_PuTTY/windows/puttygen.ico diff --git a/0.72_My_PuTTY/windows/puttygen.rc b/0.73_My_PuTTY/windows/puttygen.rc similarity index 93% rename from 0.72_My_PuTTY/windows/puttygen.rc rename to 0.73_My_PuTTY/windows/puttygen.rc index d6952d3..49c76ba 100644 --- a/0.72_My_PuTTY/windows/puttygen.rc +++ b/0.73_My_PuTTY/windows/puttygen.rc @@ -4,7 +4,7 @@ #include "rcstuff.h" -#ifdef INTEGRATED_KEYGEN +#ifdef MOD_INTEGRATED_KEYGEN #define APPNAME_KEYGEN "PuTTYgen" #define APPDESC_KEYGEN "PuTTY SSH key generation utility" @@ -28,7 +28,7 @@ FONT 8, "MS Shell Dlg" BEGIN END -#ifdef INTEGRATED_KEYGEN +#ifdef MOD_INTEGRATED_KEYGEN 810 DIALOG DISCARDABLE 0, 0, 140, 60 #else 210 DIALOG DISCARDABLE 0, 0, 140, 60 @@ -45,7 +45,7 @@ BEGIN END /* Accelerators used: cl */ -#ifdef INTEGRATED_KEYGEN +#ifdef MOD_INTEGRATED_KEYGEN 813 DIALOG DISCARDABLE 140, 40, 270, 136 #else 213 DIALOG DISCARDABLE 140, 40, 270, 136 @@ -61,7 +61,7 @@ BEGIN END /* No accelerators used */ -#ifdef INTEGRATED_KEYGEN +#ifdef MOD_INTEGRATED_KEYGEN 814 DIALOG DISCARDABLE 50, 50, 326, 239 #else 214 DIALOG DISCARDABLE 50, 50, 326, 239 @@ -75,7 +75,7 @@ BEGIN EDITTEXT 1000, 10, 10, 306, 200, ES_READONLY | ES_MULTILINE | ES_LEFT, WS_EX_STATICEDGE END -#ifndef INTEGRATED_KEYGEN +#ifndef MOD_INTEGRATED_KEYGEN #include "version.rc2" #ifndef NO_MANIFESTS diff --git a/0.72_My_PuTTY/windows/puttyins.ico b/0.73_My_PuTTY/windows/puttyins.ico similarity index 100% rename from 0.72_My_PuTTY/windows/puttyins.ico rename to 0.73_My_PuTTY/windows/puttyins.ico diff --git a/0.72_My_PuTTY/windows/puttytel.rc b/0.73_My_PuTTY/windows/puttytel.rc similarity index 100% rename from 0.72_My_PuTTY/windows/puttytel.rc rename to 0.73_My_PuTTY/windows/puttytel.rc diff --git a/0.72_My_PuTTY/windows/rcstuff.h b/0.73_My_PuTTY/windows/rcstuff.h similarity index 100% rename from 0.72_My_PuTTY/windows/rcstuff.h rename to 0.73_My_PuTTY/windows/rcstuff.h diff --git a/0.72_My_PuTTY/windows/sizetip.c b/0.73_My_PuTTY/windows/sizetip.c similarity index 100% rename from 0.72_My_PuTTY/windows/sizetip.c rename to 0.73_My_PuTTY/windows/sizetip.c diff --git a/0.72_My_PuTTY/windows/version.rc2 b/0.73_My_PuTTY/windows/version.rc2 similarity index 98% rename from 0.72_My_PuTTY/windows/version.rc2 rename to 0.73_My_PuTTY/windows/version.rc2 index 53093a3..7e068a1 100644 --- a/0.72_My_PuTTY/windows/version.rc2 +++ b/0.73_My_PuTTY/windows/version.rc2 @@ -53,7 +53,7 @@ BEGIN #else VALUE "FileVersion", TEXTVER #endif -#if (defined PERSOPORT) && (!defined FDJ) +#if (defined MOD_PERSO) && (!defined FDJ) VALUE "ProductVersion", TEXTVER " - KiTTY fork - Additional features on KiTTY That's all folks! by 9bis.com, 2019" #else VALUE "ProductVersion", TEXTVER diff --git a/0.73_My_PuTTY/windows/version_major.txt b/0.73_My_PuTTY/windows/version_major.txt new file mode 100644 index 0000000..2c21fd7 --- /dev/null +++ b/0.73_My_PuTTY/windows/version_major.txt @@ -0,0 +1 @@ +"0.73.0" diff --git a/0.73_My_PuTTY/windows/version_minor.txt b/0.73_My_PuTTY/windows/version_minor.txt new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/0.73_My_PuTTY/windows/version_minor.txt @@ -0,0 +1 @@ +2 diff --git a/0.72_My_PuTTY/windows/win_res.h b/0.73_My_PuTTY/windows/win_res.h similarity index 98% rename from 0.72_My_PuTTY/windows/win_res.h rename to 0.73_My_PuTTY/windows/win_res.h index 8f8cf03..dc45172 100644 --- a/0.72_My_PuTTY/windows/win_res.h +++ b/0.73_My_PuTTY/windows/win_res.h @@ -9,7 +9,7 @@ -#ifdef PERSOPORT +#ifdef MOD_PERSO #ifdef FDJ #define NB_ICONES 4 @@ -90,7 +90,7 @@ #define IDA_VERSION 1006 #endif -#ifdef RUTTYPORT +#ifdef MOD_RUTTY #define IDA_WEB2 1007 #endif diff --git a/0.72_My_PuTTY/windows/win_res.rc2 b/0.73_My_PuTTY/windows/win_res.rc2 similarity index 97% rename from 0.72_My_PuTTY/windows/win_res.rc2 rename to 0.73_My_PuTTY/windows/win_res.rc2 index 4cc6cbe..bc1a7bf 100644 --- a/0.72_My_PuTTY/windows/win_res.rc2 +++ b/0.73_My_PuTTY/windows/win_res.rc2 @@ -17,7 +17,7 @@ IDI_MAINICON ICON "putty.ico" -#ifdef PERSOPORT +#ifdef MOD_PERSO IDI_FILEASSOC ICON "../../res/file_assoc/kitty_assoc.ico" IDI_PUTTY_LAUNCH ICON "../../res/putty_launcher.ico" @@ -103,16 +103,16 @@ BEGIN PUSHBUTTON "View &Licence", IDA_LICENCE, 6, 118, 70, 14 PUSHBUTTON "Visit &Web Site", IDA_WEB, 140, 118, 70, 14 EDITTEXT IDA_TEXT, 10, 6, 250, 110, ES_READONLY | ES_MULTILINE | ES_CENTER, WS_EX_STATICEDGE -#if (defined PERSOPORT) && (!defined FDJ) +#if (defined MOD_PERSO) && (!defined FDJ) CTEXT "KiTTY (http://kitty.9bis.com), by 9bis.com", IDA_TEXT2, 10, 26, 194, 16 #endif -#if (defined PERSOPORT) && (defined FDJ) +#if (defined MOD_PERSO) && (defined FDJ) CTEXT "PuTTY", IDA_TEXT2, 10, 26, 194, 16 #endif END /* Accelerators used: aco */ -#if (defined PERSOPORT) && (!defined FDJ) +#if (defined MOD_PERSO) && (!defined FDJ) IDD_MAINBOX DIALOG DISCARDABLE 0, 0, 300, 610 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU /*| WS_SIZEBOX*/ #else @@ -147,7 +147,7 @@ BEGIN EDITTEXT IDA_TEXT, 10, 10, 306, 200, ES_READONLY | ES_MULTILINE | ES_LEFT, WS_EX_STATICEDGE END -#ifdef PERSOPORT +#ifdef MOD_PERSO #ifndef IDC_STATIC #define IDC_STATIC -1 @@ -227,10 +227,10 @@ END #include "../../blocnote/notepad.rc" IDI_EDITICON ICON "../../res/edit.ico" -#ifdef INTEGRATED_KEYGEN +#ifdef MOD_INTEGRATED_KEYGEN #include "puttygen.rc" #endif -#ifdef INTEGRATED_AGENT +#ifdef MOD_INTEGRATED_AGENT #include "pageant.rc" #endif diff --git a/0.72_My_PuTTY/windows/wincapi.c b/0.73_My_PuTTY/windows/wincapi.c similarity index 100% rename from 0.72_My_PuTTY/windows/wincapi.c rename to 0.73_My_PuTTY/windows/wincapi.c diff --git a/0.72_My_PuTTY/windows/wincapi.h b/0.73_My_PuTTY/windows/wincapi.h similarity index 100% rename from 0.72_My_PuTTY/windows/wincapi.h rename to 0.73_My_PuTTY/windows/wincapi.h diff --git a/0.72_My_PuTTY/windows/wincfg.c b/0.73_My_PuTTY/windows/wincfg.c similarity index 98% rename from 0.72_My_PuTTY/windows/wincfg.c rename to 0.73_My_PuTTY/windows/wincfg.c index bf37acf..3f0dd89 100644 --- a/0.72_My_PuTTY/windows/wincfg.c +++ b/0.73_My_PuTTY/windows/wincfg.c @@ -40,11 +40,11 @@ static void variable_pitch_handler(union control *ctrl, dlgparam *dlg, } } -#ifdef PERSOPORT +#ifdef MOD_PERSO #include "kitty.h" int get_param( const char * val ) ; char * get_param_str( const char * val ) ; -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) void DisableBackgroundImage( void ) ; #endif void CheckVersionFromWebSite( HWND hwnd ) ; @@ -58,7 +58,7 @@ static void checkupdate_handler(union control *ctrl, dlgparam *dlg, } } #endif -#ifdef TUTTYPORT +#ifdef MOD_TUTTY void dlg_control_enable(union control *ctrl, void *dlg, int enable); struct window_behaviour_data { union control *has_sysmenu, *window_closable, *window_minimizable, @@ -133,7 +133,7 @@ static void behaviour_handler(union control *ctrl, dlgparam *dlg, void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help, bool midsession, int protocol) { -#ifdef TUTTYPORT +#ifdef MOD_TUTTY struct window_behaviour_data *wbd; #endif struct controlset *s; @@ -148,7 +148,7 @@ void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help, c = ctrl_pushbutton(s, "About", 'a', HELPCTX(no_help), about_handler, P(hwndp)); c->generic.column = 0; -#ifdef PERSOPORT +#ifdef MOD_PERSO if (has_help) { c = ctrl_pushbutton(s, "Help", 'h', HELPCTX(no_help), help_handler, P(hwndp)); @@ -219,7 +219,7 @@ void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help, ctrl_checkbox(s, "Control-Alt is different from AltGr", 'd', HELPCTX(keyboard_ctrlalt), conf_checkbox_handler, I(CONF_ctrlaltkeys)); -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM if( cygterm_get_flag() ) ctrl_checkbox(s, "Set meta bit on alt (instead of escape)", NO_SHORTCUT, HELPCTX(no_help), @@ -448,7 +448,7 @@ void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help, ctrl_checkbox(s, "Window closes on ALT-F4", '4', HELPCTX(behaviour_altf4), conf_checkbox_handler, I(CONF_alt_f4)); -#ifdef TUTTYPORT +#ifdef MOD_TUTTY wbd = (struct window_behaviour_data *)ctrl_alloc(b, sizeof(struct window_behaviour_data)); memset(wbd, 0, sizeof(*wbd)); @@ -481,7 +481,7 @@ void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help, ctrl_checkbox(s, "Ensure window is always on top", 'e', HELPCTX(behaviour_alwaysontop), conf_checkbox_handler, I(CONF_alwaysontop)); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( !get_param("PUTTY") ) { ctrl_checkbox(s, "Send to tray on startup", NO_SHORTCUT, HELPCTX(no_help), @@ -507,7 +507,7 @@ void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help, conf_checkbox_handler, I(CONF_fullscreenonaltenter)); -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK if( !GetPuttyFlag() && GetHyperlinkFlag() ) { /* * HACK: PuttyTray / Nutty @@ -610,7 +610,7 @@ void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help, HELPCTX(ssh_tunnels_xauthority), conf_filesel_handler, I(CONF_xauthfile)); } -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM /* * cygterm back end is available on Windows. */ @@ -618,7 +618,7 @@ void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help, if (!midsession || (protocol == PROT_CYGTERM)) cygterm_setup_config_box(b, midsession); #endif -#ifdef PERSOPORT +#ifdef MOD_PERSO if( !GetPuttyFlag() && 0 ) { ctrl_settitle(b, get_param_str("NAME"), "Specific program options"); @@ -630,7 +630,7 @@ void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help, conf_filesel_handler, I(CONF_url_browser)); } -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) /* Le patch Background image ne marche plus bien sur la version PuTTY 0.61 - il est en erreur lorsqu'on passe par la config box - il est ok lorsqu'on démarrer par -load ou par duplicate session diff --git a/0.72_My_PuTTY/windows/wincons.c b/0.73_My_PuTTY/windows/wincons.c similarity index 99% rename from 0.72_My_PuTTY/windows/wincons.c rename to 0.73_My_PuTTY/windows/wincons.c index da8a240..c77d4ec 100644 --- a/0.72_My_PuTTY/windows/wincons.c +++ b/0.73_My_PuTTY/windows/wincons.c @@ -11,7 +11,7 @@ #include "storage.h" #include "ssh.h" -#ifdef PERSOPORT +#ifdef MOD_PERSO int GetAutoStoreSSHKeyFlag(void) ; #endif @@ -176,7 +176,7 @@ int console_verify_ssh_host_key( line[0] = '\0'; /* fail safe if ReadFile returns no data */ - #ifdef PERSOPORT + #ifdef MOD_PERSO if( GetAutoStoreSSHKeyFlag() ) { fprintf( stderr, "\nAutostore key is on\n" ); strcpy(line,"y\r\n"); @@ -190,7 +190,7 @@ int console_verify_ssh_host_key( ReadFile(hin, line, sizeof(line) - 1, &i, NULL); SetConsoleMode(hin, savemode); -#ifdef PERSOPORT +#ifdef MOD_PERSO } #endif diff --git a/0.72_My_PuTTY/windows/winctrls.c b/0.73_My_PuTTY/windows/winctrls.c similarity index 99% rename from 0.72_My_PuTTY/windows/winctrls.c rename to 0.73_My_PuTTY/windows/winctrls.c index 20fc3aa..7904204 100644 --- a/0.72_My_PuTTY/windows/winctrls.c +++ b/0.73_My_PuTTY/windows/winctrls.c @@ -22,10 +22,10 @@ #include -#ifdef PERSOPORT +#ifdef MOD_PERSO #include "kitty.h" #endif -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM #include #endif @@ -1651,7 +1651,7 @@ void winctrl_layout(struct dlgparam *dp, struct winctrls *wc, shortcuts[nshortcuts++] = ctrl->fileselect.shortcut; editbutton(&pos, escaped, base_id, base_id+1, "Bro&wse...", base_id+2); -#if (defined PERSOPORT) && (!defined ZMODEMPORT) +#if (defined MOD_PERSO) && (!defined MOD_ZMODEM) if(GetZModemFlag()) { shortcuts[nshortcuts++] = 'w'; } #endif shortcuts[nshortcuts++] = 'w'; @@ -1667,7 +1667,7 @@ void winctrl_layout(struct dlgparam *dp, struct winctrls *wc, data = fontspec_new("", false, 0, 0); sfree(escaped); break; -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM case CTRL_DIRECTORYSELECT: num_ids = 3; escaped = shortcut_escape(ctrl->fileselect.label, @@ -1679,9 +1679,7 @@ void winctrl_layout(struct dlgparam *dp, struct winctrls *wc, break; #endif default: - assert(!"Can't happen"); - num_ids = 0; /* placate gcc */ - break; + unreachable("bad control type in winctrl_layout"); } /* @@ -2006,7 +2004,7 @@ bool winctrl_handle_command(struct dlgparam *dp, UINT msg, } } break; -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM case CTRL_DIRECTORYSELECT: if (msg == WM_COMMAND && id == 1 && (HIWORD(wParam) == EN_SETFOCUS || HIWORD(wParam) == EN_KILLFOCUS)) @@ -2154,8 +2152,7 @@ int dlg_radiobutton_get(union control *ctrl, dlgparam *dp) for (i = 0; i < c->ctrl->radio.nbuttons; i++) if (IsDlgButtonChecked(dp->hwnd, c->base_id + 1 + i)) return i; - assert(!"No radio button was checked?!"); - return 0; + unreachable("no radio button was checked"); } void dlg_checkbox_set(union control *ctrl, dlgparam *dp, bool checked) @@ -2280,7 +2277,7 @@ int dlg_listbox_index(union control *ctrl, dlgparam *dp) return ret; } -#ifdef PERSOPORT +#ifdef MOD_PERSO int dlg_listbox_get(union control *ctrl, void *dlg, int index, char * pstr, int maxcount) { struct dlgparam *dp = (struct dlgparam *)dlg; struct winctrl *c = dlg_findbyctrl(dp, ctrl); @@ -2362,8 +2359,7 @@ void dlg_label_change(union control *ctrl, dlgparam *dp, char const *text) id = c->base_id; break; default: - assert(!"Can't happen"); - break; + unreachable("bad control type in label_change"); } if (escaped) { SetDlgItemText(dp->hwnd, id, escaped); @@ -2466,7 +2462,7 @@ void dlg_set_focus(union control *ctrl, dlgparam *dp) case CTRL_LISTBOX: id = c->base_id + 1; break; case CTRL_FILESELECT: id = c->base_id + 1; break; case CTRL_FONTSELECT: id = c->base_id + 2; break; -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM case CTRL_DIRECTORYSELECT: id = c->base_id + 1; break; #endif default: id = c->base_id; break; @@ -2627,7 +2623,7 @@ void dp_cleanup(struct dlgparam *dp) sfree(dp->errtitle); } -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM void dlg_directorysel_set(union control *ctrl, void *dlg, Filename fn) { struct dlgparam *dp = (struct dlgparam *)dlg; @@ -2645,7 +2641,7 @@ void dlg_directorysel_get(union control *ctrl, void *dlg, Filename *fn) fn->path[lenof(fn->path)-1] = '\0'; } #endif -#ifdef TUTTYPORT +#ifdef MOD_TUTTY void dlg_control_hide(union control *ctrl, void *dlg) { struct dlgparam *dp = (struct dlgparam *) dlg; diff --git a/0.72_My_PuTTY/windows/windefs.c b/0.73_My_PuTTY/windows/windefs.c similarity index 100% rename from 0.72_My_PuTTY/windows/windefs.c rename to 0.73_My_PuTTY/windows/windefs.c diff --git a/0.72_My_PuTTY/windows/windlg.c b/0.73_My_PuTTY/windows/windlg.c similarity index 99% rename from 0.72_My_PuTTY/windows/windlg.c rename to 0.73_My_PuTTY/windows/windlg.c index 98a2147..1facc30 100644 --- a/0.72_My_PuTTY/windows/windlg.c +++ b/0.73_My_PuTTY/windows/windlg.c @@ -50,7 +50,7 @@ static char *events_circular[LOGEVENT_CIRCULAR_MAX]; static int ninitial = 0, ncircular = 0, circular_first = 0; -#ifdef PERSOPORT +#ifdef MOD_PERSO #include #include #include "kitty.h" @@ -76,7 +76,7 @@ int print_event_log( FILE * fp, int i ) { return 1 ; } #endif -#ifdef PRINTCLIPPORT +#ifdef MOD_PRINTCLIP #define PRINT_TO_CLIPBOARD_STRING "Windows clipboard" #endif @@ -236,7 +236,7 @@ static INT_PTR CALLBACK LicenceProc(HWND hwnd, UINT msg, -#if (defined PERSOPORT) && (!defined FDJ) +#if (defined MOD_PERSO) && (!defined FDJ) //static const char MESSAGE[] = ""; static const char MESSAGE[] = " KiTTY software is developed by Cyd for 9bis.com, copyright \251 2006-2019, thanks to Leo for bcrypt and mini libraries, thanks to all contributors " ; @@ -492,7 +492,7 @@ static INT_PTR CALLBACK AboutProc(HWND hwnd, UINT msg, SetDlgItemText(hwnd, IDA_TEXT, text); sfree(text); } -#ifdef PERSOPORT +#ifdef MOD_PERSO if( get_param("PUTTY") ) SetDlgItemText(hwnd, IDA_TEXT2, "" ) ; #endif return 1; @@ -672,7 +672,7 @@ static INT_PTR CALLBACK GenericMainDlgProc(HWND hwnd, UINT msg, switch (msg) { case WM_INITDIALOG: -#ifdef PERSOPORT +#ifdef MOD_PERSO { RECT rcClient ; int h ; @@ -863,7 +863,7 @@ static INT_PTR CALLBACK GenericMainDlgProc(HWND hwnd, UINT msg, * spurious firing during the above setup procedure. */ SetWindowLongPtr(hwnd, GWLP_USERDATA, 1); -#ifdef PERSOPORT +#ifdef MOD_PERSO ShowWindow(hwnd,SW_HIDE); ShowWindow(hwnd,SW_SHOW); #endif @@ -968,7 +968,7 @@ static INT_PTR CALLBACK GenericMainDlgProc(HWND hwnd, UINT msg, void modal_about_box(HWND hwnd) { EnableWindow(hwnd, 0); -#if (defined PERSOPORT) && (!defined FDJ) +#if (defined MOD_PERSO) && (!defined FDJ) if( get_param("PUTTY") ) DialogBox(hinst, MAKEINTRESOURCE(IDD_ABOUTBOX), hwnd, AboutProcOrig); else DialogBox(hinst, MAKEINTRESOURCE(IDD_KITTYABOUT), hwnd, AboutProc); #else @@ -1004,7 +1004,7 @@ bool do_config(void) { bool ret; -#ifdef PERSOPORT +#ifdef MOD_PERSO // On cree la session "Default Settings" si elle n'existe pas if( GetDefaultSettingsFlag() ) { char buffer[1024] ; @@ -1035,7 +1035,7 @@ bool do_config(void) winctrl_cleanup(&ctrls_base); dp_cleanup(&dp); -#ifdef PERSOPORT +#ifdef MOD_PERSO GotoConfigDirectory() ; if( ret==false ) SaveRegistryKey( ) ; // On sort de la config box par ESCAPE ou cancel else _beginthread( routine_SaveRegistryKey, 0, (void*)NULL ) ; // On démarre une session @@ -1076,7 +1076,7 @@ bool do_reconfig(HWND hwnd, int protcfginfo) if (!ret) conf_copy_into(conf, backup_conf); -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) if( GetBackgroundImageFlag() && (conf_get_int(conf,CONF_bg_slideshow)!=conf_get_int(backup_conf,CONF_bg_slideshow)) ) { KillTimer( hwnd, TIMER_SLIDEBG ) ; if((conf_get_int(conf,CONF_bg_type)!=0)&&(conf_get_int(conf,CONF_bg_slideshow)>0)) @@ -1143,7 +1143,7 @@ void showeventlog(HWND hwnd) SetActiveWindow(logbox); } -#if (defined PERSOPORT) && (!defined FDJ) +#if (defined MOD_PERSO) && (!defined FDJ) void showabout(HWND hwnd) { /* @@ -1220,7 +1220,7 @@ int win_seat_verify_ssh_host_key( char *text = dupprintf(wrongmsg, appname, keytype, fingerprint, appname); char *caption = dupprintf(mbtitle, appname); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( GetAutoStoreSSHKeyFlag() ) { lp_eventlog(default_logpolicy, "Auto update host key") ; mbret=IDYES ; @@ -1234,7 +1234,7 @@ int win_seat_verify_ssh_host_key( sfree(caption); if (mbret == IDYES) { store_host_key(host, port, keytype, keystr); -#ifdef PERSOPORT +#ifdef MOD_PERSO SaveRegistryKey() ; #endif return 1; @@ -1244,7 +1244,7 @@ int win_seat_verify_ssh_host_key( int mbret; char *text = dupprintf(absentmsg, keytype, fingerprint, appname); char *caption = dupprintf(mbtitle, appname); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( GetAutoStoreSSHKeyFlag() ) { lp_eventlog(default_logpolicy, "Auto store host key") ; mbret=IDYES ; @@ -1258,7 +1258,7 @@ int win_seat_verify_ssh_host_key( sfree(caption); if (mbret == IDYES) { store_host_key(host, port, keytype, keystr); -#ifdef PERSOPORT +#ifdef MOD_PERSO SaveRegistryKey() ; #endif return 1; diff --git a/0.72_My_PuTTY/windows/window.c b/0.73_My_PuTTY/windows/window.c similarity index 98% rename from 0.72_My_PuTTY/windows/window.c rename to 0.73_My_PuTTY/windows/window.c index 1f48536..e78da86 100644 --- a/0.72_My_PuTTY/windows/window.c +++ b/0.73_My_PuTTY/windows/window.c @@ -170,7 +170,7 @@ struct agent_callback { #define FONT_UNDERLINE 2 #define FONT_BOLDUND 3 -#ifdef PERSOPORT +#ifdef MOD_PERSO #define FONT_ITALIC 4 #define FONT_WIDE 0x08 #define FONT_HIGH 0x10 @@ -211,7 +211,7 @@ static enum { static int descent; #ifndef NCFGCOLOURS -#ifdef PERSOPORT +#ifdef MOD_PERSO #define NCFGCOLOURS 34 #else #define NCFGCOLOURS 22 @@ -230,15 +230,15 @@ static RGBTRIPLE defpal[NALLCOLOURS]; static HBITMAP caretbm; -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK #include "urlhack.h" static int urlhack_cursor_is_hand = 0; void urlhack_enable(void); #endif -#ifdef SAVEDUMPPORT +#ifdef MOD_SAVEDUMP void SaveDump( void ) ; #endif -#ifdef PERSOPORT +#ifdef MOD_PERSO #include #include #include @@ -312,31 +312,31 @@ int force_reconf = 1 ; // Reinitialiser le fichier de logs void logfile_reinit(void *handle) ; -#ifdef INTEGRATED_KEYGEN +#ifdef MOD_INTEGRATED_KEYGEN int WINAPI KeyGen_WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show); #endif -#ifdef INTEGRATED_AGENT +#ifdef MOD_INTEGRATED_AGENT int WINAPI Agent_WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show); #endif #endif -#ifdef WTSPORT +#ifdef MOD_WTS typedef enum _WTS_VIRTUAL_CLASS { WTSVirtualClientData, WTSVirtualFileHandle } WTS_VIRTUAL_CLASS; // WTS_VIRTUAL_CLASS n'est pas défini dans le fichier wtsapi32.h !!! #include #endif -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) #include "../../kitty_image.h" #endif -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT static time_t last_reconnect = 0; void SetConnBreakIcon( void ) ; static void close_session(void *ignored_context); #endif /* rutty: */ -#ifdef RUTTYPORT +#ifdef MOD_RUTTY #define IDM_SCRIPT (0x5100) #define IDM_SCRIPTSEND (0x5110) #define IDM_SCRIPTHALT (0x5120) @@ -543,7 +543,7 @@ static void start_backend(void) MessageBox(NULL, msg, str, MB_ICONERROR | MB_OK); sfree(str); sfree(msg); -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT if( GetAutoreconnectFlag() && conf_get_int(conf,CONF_failure_reconnect) && is_backend_first_connected ) { SetConnBreakIcon() ; SetSSHConnected(0) ; @@ -591,7 +591,7 @@ static void start_backend(void) session_closed = false; /* rutty: */ -#ifdef RUTTYPORT +#ifdef MOD_RUTTY script_init(&scriptdata, conf); if(conf_get_int(conf, CONF_script_mode) == SCRIPT_PLAY && !filename_is_null(conf_get_filename(conf, CONF_script_filename))) script_sendfile(&scriptdata, conf_get_filename(conf, CONF_script_filename)); @@ -609,7 +609,7 @@ static void close_session(void *ignored_context) session_closed = true; newtitle = dupprintf("%s (inactive)", appname); -#ifdef PERSOPORT +#ifdef MOD_PERSO newtitle = dupprintf("%s (inactive)", conf_get_str(conf,CONF_wintitle)); #endif win_set_icon_title(wintw, newtitle); @@ -638,7 +638,7 @@ static void close_session(void *ignored_context) } } -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM /* Copy at most n characters from src to dst or until copying a '\0' * character. A pointer to the terminal '\0' in dst is returned, or if no * '\0' was written, dst+n is returned. */ @@ -652,7 +652,7 @@ stpcpy_max(char *dst, const char *src, size_t n) bool get_got_host(void) ; void set_got_host(bool val ) ; #endif -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT void RestartSession( void ) { win_seat_connection_fatal( win_seat, "User request session restart..." ) ; PostMessage(hwnd,WM_KEYDOWN,VK_RETURN ,0) ; @@ -667,7 +667,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) int guess_width, guess_height; dll_hijacking_protection(); -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM struct netscheduler_tag *netsc = NULL ; #endif @@ -704,15 +704,15 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) init_winfuncs(); conf = conf_new(); -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK urlhack_init(); #endif -#ifdef PERSOPORT +#ifdef MOD_PERSO // Initialisation specifique a KiTTY SethInstIcons( hinst ) ; InitWinMain(); #endif -#ifdef NO_TRANSPARENCY +#ifdef MOD_NOTRANSPARENCY SetTransparencyFlag(0); #endif @@ -778,7 +778,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) while (i > 1 && isspace(p[i - 1])) i--; p[i] = '\0'; -#ifdef PERSOPORT +#ifdef MOD_PERSO if( GetDirectoryBrowseFlag() ) { char * pfolder ; if( (pfolder=strstr(p+1," -folder \"")) ) { @@ -845,8 +845,8 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) i++; /* skip next argument */ } else if (ret == 1) { continue; /* nothing further needs doing */ -#ifdef PERSOPORT -#ifndef NO_PASSWORD +#ifdef MOD_PERSO +#ifndef MOD_NOPASSWORD } else if( !strcmp(p, "-pass") ) { i++ ; char bufpass[1024] ; @@ -856,7 +856,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) memset( bufpass, 0, strlen(bufpass) ) ; memset( argv[i], 0, strlen(argv[i]) ) ; #endif -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM } else if( !strcmp(p, "-cc") ) { conf_set_str( conf, CONF_host, "cmd.exe /k" ) ; conf_set_int( conf, CONF_port, 0 ) ; @@ -938,33 +938,33 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) } else if( !strcmp(p, "-notrans") ) { SetTransparencyFlag( 0 ) ; conf_set_int(conf,CONF_transparencynumber, -1) ; -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM } else if( !strcmp(p, "-cygterm") ) { cygterm_set_flag( 1 ) ; } else if( !strcmp(p, "-nocygterm") ) { cygterm_set_flag( 0 ) ; #endif -#ifdef SAVEDUMPPORT +#ifdef MOD_SAVEDUMP } else if( !strcmp(p, "-savedump") ) { SaveDump() ; return 0; #endif -#ifdef RUTTYPORT +#ifdef MOD_RUTTY } else if( !strcmp(p, "-norutty") ) { SetRuttyFlag( 0 ) ; #endif -#ifdef ADBPORT +#ifdef MOD_ADB } else if( !strcmp(p, "-adb") ) { SetADBFlag( 1 ) ; #endif -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM } else if( !strcmp(p, "-zmodem") ) { SetZModemFlag( 1 ) ; } else if( !strcmp(p, "-nozmodem") ) { SetZModemFlag( 0 ) ; #endif -#ifdef HYPERLINKPORT -#ifndef NO_HYPERLINK +#ifdef MOD_HYPERLINK +#ifndef MOD_NOHYPERLINK } else if( !strcmp(p, "-hyperlink") ) { HyperlinkFlag = 1 ; } else if( !strcmp(p, "-nohyperlink") ) { @@ -987,7 +987,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) if( conf_get_int( conf, CONF_xpos)<0) conf_set_int( conf, CONF_xpos,0); conf_set_bool( conf, CONF_save_windowpos, true ) ; } -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) } else if( !strcmp(p, "-nobgimage") ) { SetBackgroundImageFlag(0) ; } else if( !strcmp(p, "-bgimage") ) { @@ -1013,16 +1013,16 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) SetRuttyFlag( 0 ) ; SetDefaultSettingsFlag(1); SetReadOnlyFlag(0); -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM cygterm_set_flag( 0 ) ; #endif -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) SetBackgroundImageFlag(0) ; #endif -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT SetAutoreconnectFlag( 0 ) ; #endif -#ifdef ADBPORT +#ifdef MOD_ADB SetADBFlag(0); #endif SetSessionFilterFlag( 0 ) ; @@ -1050,19 +1050,19 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) i++; sprintf(buffer, "%s|%s|%s", (char*)get_param_str("INI"), (char*)get_param_str("SAV"), argv[i] ) ; return Notepad_WinMain(inst, prev, buffer, show) ; -#ifdef LAUNCHERPORT +#ifdef MOD_LAUNCHER } else if( !strcmp(p, "-launcher") ) { char *np; np=strstr(cmdline,"-launcher")+9; return Launcher_WinMain(inst, prev, np, show) ; #endif -#ifdef INTEGRATED_KEYGEN +#ifdef MOD_INTEGRATED_KEYGEN } else if( !strcmp(p, "-keygen") ) { char *np; np=strstr(cmdline,"-keygen")+7; return KeyGen_WinMain(inst, prev, np, show) ; #endif -#ifdef INTEGRATED_AGENT +#ifdef MOD_INTEGRATED_AGENT } else if( !strcmp(p, "-runagent") ) { char *np; np=strstr(cmdline,"-runagent")+9; @@ -1132,7 +1132,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) pgp_fingerprints(); exit(1); } else if (*p != '-') { -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM } else if ( conf_get_int(conf,CONF_protocol) == PROT_CYGTERM) { /* Concatenate all the remaining arguments separating * them with spaces to get the command line to execute. @@ -1162,7 +1162,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) } } -#ifdef PERSOPORT +#ifdef MOD_PERSO // Creation du fichier kitty.ini par defaut si besoin CreateDefaultIniFile() ; #endif @@ -1180,7 +1180,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) prepare_session(conf); } -#ifdef PERSOPORT +#ifdef MOD_PERSO HICON icon_m ; if( GetIconeFlag() > 0 ) icon_m = LoadIcon( GethInstIcons(), MAKEINTRESOURCE(IDI_MAINICON_0 + GetIconeNum() ) ); @@ -1211,12 +1211,12 @@ if( conf_get_int(conf,CONF_icone) == 0 ) { wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; -#ifdef PERSOPORT +#ifdef MOD_PERSO if( conf_get_int(conf, CONF_ctrl_tab_switch) && GetCtrlTabFlag() ) wndclass.cbWndExtra += 8; #endif wndclass.hInstance = inst; -#ifdef PERSOPORT +#ifdef MOD_PERSO wndclass.hIcon = icon_m; #else wndclass.hIcon = LoadIcon(inst, MAKEINTRESOURCE(IDI_MAINICON)); @@ -1224,7 +1224,7 @@ if( conf_get_int(conf,CONF_icone) == 0 ) { wndclass.hCursor = LoadCursor(NULL, IDC_IBEAM); wndclass.hbrBackground = NULL; wndclass.lpszMenuName = NULL; -#if (defined PERSOPORT) && (!defined FDJ) +#if (defined MOD_PERSO) && (!defined FDJ) wndclass.lpszClassName = dup_mb_to_wc(DEFAULT_CODEPAGE, 0, KiTTYClassName); #else wndclass.lpszClassName = dup_mb_to_wc(DEFAULT_CODEPAGE, 0, appname); @@ -1232,7 +1232,7 @@ if( conf_get_int(conf,CONF_icone) == 0 ) { RegisterClassW(&wndclass); } -#ifdef PERSOPORT +#ifdef MOD_PERSO // Initialisation de la structure NOTIFYICONDATA TrayIcone.cbSize = sizeof(TrayIcone); // On alloue la taille necessaire pour la structure TrayIcone.uID = IDI_MAINICON_0 ; // On lui donne un ID @@ -1272,7 +1272,7 @@ TrayIcone.hWnd = hwnd ; if (guess_height > r.bottom - r.top) guess_height = r.bottom - r.top; } -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) const char* winname = appname; #endif { @@ -1285,7 +1285,7 @@ TrayIcone.hWnd = hwnd ; winmode &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX); if (conf_get_bool(conf, CONF_alwaysontop)) exwinmode |= WS_EX_TOPMOST; -#ifdef TUTTYPORT +#ifdef MOD_TUTTY if (!conf_get_int(conf, CONF_window_has_sysmenu)) winmode &= ~(WS_SYSMENU); if (!conf_get_int(conf, CONF_window_minimizable)) @@ -1295,8 +1295,8 @@ TrayIcone.hWnd = hwnd ; #endif if (conf_get_bool(conf, CONF_sunken_edge)) exwinmode |= WS_EX_CLIENTEDGE; -#ifdef PERSOPORT -#if (defined IMAGEPORT) && (!defined FDJ) +#ifdef MOD_PERSO +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) // TODO: This is the beginning of some work to have windows with fancy // no-client-edge borders. It's not ready yet. if( GetBackgroundImageFlag() && (!GetPuttyFlag()) ) @@ -1389,7 +1389,7 @@ TrayIcone.hWnd = hwnd ; guess_height = extra_height + font_height * term->rows; SetWindowPos(hwnd, NULL, 0, 0, guess_width, guess_height, SWP_NOMOVE | SWP_NOREDRAW | SWP_NOZORDER); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( !PuttyFlag ) if( (conf_get_bool(conf,CONF_saveonexit)||conf_get_bool(conf,CONF_save_windowpos)) && (xpos_init>=0) && (ypos_init>=0) ) { @@ -1441,7 +1441,7 @@ TrayIcone.hWnd = hwnd ; char *str; popup_menus[SYSMENU].menu = GetSystemMenu(hwnd, false); -#ifdef TUTTYPORT +#ifdef MOD_TUTTY EnableMenuItem(popup_menus[SYSMENU].menu, SC_CLOSE, conf_get_int(conf,CONF_window_closable) ? MF_ENABLED : MF_GRAYED); #endif popup_menus[CTXMENU].menu = CreatePopupMenu(); @@ -1456,22 +1456,22 @@ TrayIcone.hWnd = hwnd ; m = popup_menus[j].menu; AppendMenu(m, MF_SEPARATOR, 0, 0); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( !PuttyFlag ) InitSpecialMenu( m, conf_get_str(conf,CONF_folder), conf_get_str(conf,CONF_sessionname) ) ; #endif /* rutty: */ -#ifdef RUTTYPORT +#ifdef MOD_RUTTY AppendMenu(m, MF_ENABLED, IDM_SCRIPTSEND, "Send recorded &script file" ) ; AppendMenu(m, MF_SEPARATOR, 0, 0); #endif /* rutty */ AppendMenu(m, MF_ENABLED, IDM_SHOWLOG, "&Event Log"); -#ifdef PERSOPORT +#ifdef MOD_PERSO AppendMenu(m, MF_ENABLED, IDM_EXPORTSETTINGS, "Export ¤t settings" ) ; #endif AppendMenu(m, MF_SEPARATOR, 0, 0); AppendMenu(m, MF_ENABLED, IDM_NEWSESS, "Ne&w Session..."); AppendMenu(m, MF_ENABLED, IDM_DUPSESS, "&Duplicate Session"); -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT AppendMenu(m, MF_ENABLED, IDM_RESTARTSESSION, "Close+Restart") ; #endif AppendMenu(m, MF_POPUP | MF_ENABLED, (UINT_PTR) savedsess_menu, @@ -1480,7 +1480,7 @@ TrayIcone.hWnd = hwnd ; AppendMenu(m, MF_SEPARATOR, 0, 0); AppendMenu(m, MF_ENABLED, IDM_COPYALL, "C&opy All to Clipboard"); AppendMenu(m, MF_ENABLED, IDM_CLRSB, "C&lear Scrollback"); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( conf_get_int(conf, CONF_logtype)!=LGTYP_NONE ) { AppendMenu(m, MF_ENABLED, IDM_CLEARLOGFILE, "Clear log file"); } else { @@ -1492,7 +1492,7 @@ TrayIcone.hWnd = hwnd ; AppendMenu(m, (conf_get_int(conf, CONF_resize_action) == RESIZE_DISABLED) ? MF_GRAYED : MF_ENABLED, IDM_FULLSCREEN, "&Full Screen"); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( !PuttyFlag ) { // if( !IsWow64() ) { AppendMenu(m, MF_ENABLED, IDM_PRINT, "Print clip&board") ; } // Le menu print clipboard avait été desactivé un temps sur les machine 64bits AppendMenu(m, MF_ENABLED, IDM_PRINT, "Print clip&board") ; @@ -1520,14 +1520,14 @@ TrayIcone.hWnd = hwnd ; AppendMenu(m, MF_ENABLED, IDM_SHOWPORTFWD, "Po&rt forwarding"); -#ifdef PORTKNOCKINGPORT +#ifdef MOD_PORTKNOCKING if( strlen(conf_get_str(conf,CONF_portknockingoptions))>0 ) { AppendMenu(m, MF_ENABLED, IDM_PORTKNOCK, "Port &knock"); } #endif } #endif -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM if( (!GetPuttyFlag()) && GetZModemFlag() ) { AppendMenu(m, MF_SEPARATOR, 0, 0); // AppendMenu(m, term->xyz_transfering?MF_GRAYED:MF_ENABLED, IDM_XYZSTART, "&Zmodem Receive"); @@ -1544,7 +1544,7 @@ TrayIcone.hWnd = hwnd ; sfree(str); } } -#ifdef PERSOPORT +#ifdef MOD_PERSO // SETTINGS specifique a la session if( !PuttyFlag ) { @@ -1580,7 +1580,7 @@ TrayIcone.hWnd = hwnd ; } } -#ifndef NO_TRANSPARENCY +#ifndef MOD_NOTRANSPARENCY if( GetTransparencyFlag() && conf_get_int(conf,CONF_transparencynumber) != -1 ) { if( conf_get_int(conf,CONF_transparencynumber) > 0 ) { SetTransparency( hwnd, 255-conf_get_int(conf,CONF_transparencynumber) ) ; @@ -1598,7 +1598,7 @@ TrayIcone.hWnd = hwnd ; } // Lancement des timer (changement image de fond, rafraichissement) -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) if( (!GetBackgroundImageFlag()) || GetPuttyFlag() ) conf_set_int(conf,CONF_bg_type,0); if( conf_get_int(conf,CONF_bg_type)!=0 ) { if(conf_get_int(conf,CONF_bg_slideshow)>0) @@ -1617,7 +1617,7 @@ TrayIcone.hWnd = hwnd ; SetTimer(hwnd, TIMER_ANTIIDLE, (int)(30*1000), NULL) ; } // fin de if( !PuttyFlag ) -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK else { conf_set_int(conf,CONF_url_underline,URLHACK_UNDERLINE_NEVER); } @@ -1625,7 +1625,7 @@ else { #endif -#ifdef PORTKNOCKINGPORT +#ifdef MOD_PORTKNOCKING ManagePortKnocking(conf_get_str(conf,CONF_host),conf_get_str(conf,CONF_portknockingoptions)); #endif @@ -1634,11 +1634,11 @@ ManagePortKnocking(conf_get_str(conf,CONF_host),conf_get_str(conf,CONF_portknock } start_backend(); -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT if (conf_get_int(conf, CONF_protocol) != PROT_SSH) { is_backend_first_connected = 1 ; } last_reconnect = time(NULL); #endif -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK /* * HACK: PuttyTray / Nutty * Hyperlink stuff: Set the regular expression @@ -1675,7 +1675,7 @@ ManagePortKnocking(conf_get_str(conf,CONF_host),conf_get_str(conf,CONF_portknock term_set_focus(term, GetForegroundWindow() == hwnd); UpdateWindow(hwnd); -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM if( (!GetPuttyFlag()) && GetZModemFlag() ) { netsc = netscheduler_new(); } @@ -1720,7 +1720,7 @@ ManagePortKnocking(conf_get_str(conf,CONF_host),conf_get_str(conf,CONF_portknock if ((unsigned)(n - WAIT_OBJECT_0) < (unsigned)nhandles) { handle_got_event(handles[n - WAIT_OBJECT_0]); sfree(handles); -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM if( (!GetPuttyFlag()) && GetZModemFlag() ) { continue ; } #endif } else @@ -1732,7 +1732,7 @@ ManagePortKnocking(conf_get_str(conf,CONF_host),conf_get_str(conf,CONF_portknock if (!(IsWindow(logbox) && IsDialogMessage(logbox, &msg))) DispatchMessageW(&msg); -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM if( (!GetPuttyFlag()) && GetZModemFlag() && xyz_Process(backend, backend, term)) continue; #endif @@ -1764,7 +1764,7 @@ ManagePortKnocking(conf_get_str(conf,CONF_host),conf_get_str(conf,CONF_portknock } finished: -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM if( (!GetPuttyFlag()) && GetZModemFlag() ) { netscheduler_free(netsc); } @@ -1805,7 +1805,7 @@ void cleanup_exit(int code) /* * Clean up. */ -#ifdef PERSOPORT +#ifdef MOD_PERSO chdir( InitialDirectory ) ; if( conf_get_bool(conf,CONF_saveonexit) ) { SaveWindowCoord( conf ) ; } @@ -1847,7 +1847,7 @@ void cleanup_exit(int code) } } #endif -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK urlhack_cleanup(); #endif deinit_fonts(); @@ -2042,7 +2042,7 @@ static void wintw_set_raw_mouse_mode(TermWin *tw, bool activate) */ static void win_seat_connection_fatal(Seat *seat, const char *msg) { -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT if( GetAutoreconnectFlag() && is_backend_first_connected ) { SetConnBreakIcon() ; SetSSHConnected(0); @@ -2123,7 +2123,7 @@ static void conftopalette(void) static const int ww[] = { 256, 257, 258, 259, 260, 261, 0, 8, 1, 9, 2, 10, 3, 11, -#ifdef TUTTYPORT +#ifdef MOD_TUTTY 4, 12, 5, 13, 6, 14, 7, 15, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273 @@ -2428,7 +2428,7 @@ static void init_fonts(int pick_width, int pick_height) font_width = pick_width; quality = conf_get_int(conf, CONF_font_quality); -#ifdef PERSOPORT +#ifdef MOD_PERSO #define f(i,c,w,u,t) \ fonts[i] = CreateFont (font_height, font_width, 0, 0, w, t, u, FALSE, \ c, OUT_DEFAULT_PRECIS, \ @@ -2488,7 +2488,7 @@ static void init_fonts(int pick_width, int pick_height) GetCPInfo(ucsdata.font_codepage, &cpinfo); ucsdata.dbcs_screenfont = (cpinfo.MaxCharSize > 1); } -#ifdef PERSOPORT +#ifdef MOD_PERSO /* Check whether italic face is acceptable... */ f(FONT_ITALIC, font->charset, fw_dontcare, FALSE, TRUE); @@ -2594,7 +2594,7 @@ static void init_fonts(int pick_width, int pick_height) } if (bold_font_mode == BOLD_FONT) { -#ifdef PERSOPORT +#ifdef MOD_PERSO f(FONT_BOLD, font->charset, fw_bold, FALSE, FALSE); #else f(FONT_BOLD, font->charset, fw_bold, false); @@ -2648,7 +2648,7 @@ static void another_font(int fontno) { int basefont; int fw_dontcare, fw_bold, quality; -#ifdef PERSOPORT +#ifdef MOD_PERSO int c, w, x ; bool t; #else @@ -2680,7 +2680,7 @@ static void another_font(int fontno) u = false; s = font->name; x = font_width; -#ifdef PERSOPORT +#ifdef MOD_PERSO t = false; #endif @@ -2694,7 +2694,7 @@ static void another_font(int fontno) w = fw_bold; if (fontno & FONT_UNDERLINE) u = true; -#ifdef PERSOPORT +#ifdef MOD_PERSO if (fontno & FONT_ITALIC && use_italics) t = true; #endif @@ -2703,7 +2703,7 @@ static void another_font(int fontno) fonts[fontno] = CreateFont(font_height * (1 + !!(fontno & FONT_HIGH)), x, 0, 0, w, -#ifdef PERSOPORT +#ifdef MOD_PERSO t, u, FALSE, c, OUT_DEFAULT_PRECIS, #else false, u, false, c, OUT_DEFAULT_PRECIS, @@ -2995,7 +2995,7 @@ static void reset_window(int reinit) { } } -#ifdef PERSOPORT +#ifdef MOD_PERSO void ResetWindow(int reinit) { reset_window( reinit ) ; } #endif @@ -3079,10 +3079,10 @@ static bool is_alt_pressed(void) return true; return false; } -#if (!defined IMAGEPORT) || (defined FDJ) +#if (!defined MOD_BACKGROUNDIMAGE) || (defined FDJ) static bool resizing; #endif -#ifdef PERSOPORT +#ifdef MOD_PERSO struct ctrl_tab_info { int direction; HWND self; @@ -3097,7 +3097,7 @@ struct ctrl_tab_info { static BOOL CALLBACK CtrlTabWindowProc(HWND hwnd, LPARAM lParam) { struct ctrl_tab_info* info = (struct ctrl_tab_info*) lParam; char lpszClassName[256]; -#if (defined PERSOPORT) && (!defined FDJ) +#if (defined MOD_PERSO) && (!defined FDJ) strcpy(lpszClassName,KiTTYClassName) ; #else strcpy(lpszClassName,appname) ; @@ -3146,7 +3146,7 @@ static void win_seat_notify_remote_exit(Seat *seat) /* exitcode == INT_MAX indicates that the connection was closed * by a fatal error, so an error box will be coming our way and * we should not generate this informational one. */ -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT if( GetAutoreconnectFlag() && is_backend_first_connected ) { SetConnBreakIcon() ; SetSSHConnected(0); @@ -3184,7 +3184,7 @@ static void conf_cache_data(void) } static const int clips_system[] = { CLIP_SYSTEM }; -#ifdef PERSOPORT +#ifdef MOD_PERSO void kitty_term_copyall(Terminal *term) { term_copyall(term,clips_system,lenof(clips_system)) ; } #endif @@ -3220,7 +3220,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, static bool processed_resize = false; static UINT last_mousemove = 0; int resize_action; -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK /* * HACK: PuttyTray / Nutty */ @@ -3238,7 +3238,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, } else { } } -#ifdef PERSOPORT +#ifdef MOD_PERSO else if((UINT_PTR)wParam == TIMER_INIT) { // Initialisation char buffer[4096] = "" ; @@ -3360,7 +3360,7 @@ else if((UINT_PTR)wParam == TIMER_AUTOPASTE) { // AutoPaste } } } -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) else if( GetBackgroundImageFlag() && ((UINT_PTR)wParam == TIMER_SLIDEBG) ) { // Changement automatique de l'image de fond NextBgImage( hwnd ) ; InvalidateRect( hwnd, NULL, true ) ; @@ -3377,7 +3377,7 @@ else if((UINT_PTR)wParam == TIMER_ANTIIDLE) { // Envoi de l'anti-idle if(strlen( conf_get_str(conf,CONF_antiidle) ) > 0) SendAutoCommand( hwnd, conf_get_str(conf,CONF_antiidle) ) ; else if( strlen( AntiIdleStr ) > 0 ) SendAutoCommand( hwnd, AntiIdleStr ) ; } -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT if(!backend||!is_backend_connected) { // On essaie de se reconnecter en cas de problème de connexion if ( conf_get_int(conf,CONF_failure_reconnect) && is_backend_first_connected ) { lp_eventlog(default_logpolicy, "No connection, trying to reconnect...") ; @@ -3408,7 +3408,7 @@ else if((UINT_PTR)wParam == TIMER_BLINKTRAYICON) { // Clignotement de l'icone d } } } -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT else if((UINT_PTR)wParam == TIMER_RECONNECT) { if( !backend && GetAutoreconnectFlag() ) { lp_eventlog(default_logpolicy, "No backend connection, reconnecting...") ; @@ -3424,7 +3424,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation #endif return 0; case WM_CREATE: -#ifdef PERSOPORT +#ifdef MOD_PERSO { // Initialiation MainHwnd = hwnd ; @@ -3439,7 +3439,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation SetTransparency( hwnd, 255-conf_get_int(conf,CONF_transparencynumber) ) ; } -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) if( GetIconeFlag() == -1 ) conf_set_int( conf, CONF_bg_type, 0 ) ; if( !GetBackgroundImageFlag() ) conf_set_int( conf, CONF_bg_type, 0 ); #endif @@ -3453,7 +3453,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation SetWindowLong(hwnd, wndExtra - 8, filetime.dwHighDateTime); SetWindowLong(hwnd, wndExtra - 4, filetime.dwLowDateTime); } -#ifdef WTSPORT +#ifdef MOD_WTS WTSRegisterSessionNotification(hwnd,NOTIFY_FOR_THIS_SESSION); #endif } @@ -3461,7 +3461,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation break; case WM_CLOSE: { -#ifdef PERSOPORT +#ifdef MOD_PERSO if( GetProtectFlag() ) { MessageBox(hwnd, "You are not allowed to close a protected window", @@ -3472,7 +3472,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation show_mouseptr(1); str = dupprintf("%s Exit Confirmation", appname); -#ifdef RUTTYPORT +#ifdef MOD_RUTTY /* rutty: */ if (scriptdata.runs) { @@ -3493,7 +3493,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation "Are you sure you want to close this session?", str, MB_ICONWARNING | MB_OKCANCEL | MB_DEFBUTTON1) == IDOK) { -#ifdef RUTTYPORT +#ifdef MOD_RUTTY script_record_stop(&scriptdata); #endif if( strlen( conf_get_str(conf,CONF_autocommandout) ) > 0 ) { //Envoie d'une command automatique en sortant @@ -3533,7 +3533,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation break; case WM_COMMAND: case WM_SYSCOMMAND: -#ifdef PERSOPORT +#ifdef MOD_PERSO if( strlen( conf_get_str(conf,CONF_folder) )>0 ) SetInitCurrentFolder( conf_get_str(conf,CONF_folder) ); if( (wParam>=IDM_USERCMD)&&(wParam<(IDM_USERCMD+NB_MENU_MAX)) ) { ManageSpecialCommand( hwnd, wParam-IDM_USERCMD ) ; @@ -3549,7 +3549,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation case IDM_SAVEDSESS: { char b[2048]; -#ifdef PERSOPORT +#ifdef MOD_PERSO char *cl=NULL; #else char *cl; @@ -3604,7 +3604,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation if (sessno < (unsigned)sesslist.nsessions) { const char *session = sesslist.sessions[sessno]; cl = dupprintf("putty %s@%s", argprefix, session); -#ifdef PERSOPORT +#ifdef MOD_PERSO GetSessionFolderName( conf_get_str(conf,CONF_sessionname), conf_get_str(conf,CONF_folder) ) ; if( GetDirectoryBrowseFlag() ) if( strcmp(conf_get_str(conf,CONF_folder), "")&&strcmp(conf_get_str(conf,CONF_folder),"Default") ) { strcat( cl, " -folder \"" ) ; strcat( cl, conf_get_str(conf,CONF_folder) ) ; strcat( cl, "\"" ) ; } @@ -3612,7 +3612,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation inherit_handles = false; } else break; -#ifdef PERSOPORT +#ifdef MOD_PERSO } else /* IDM_NEWSESS */ { if( strcmp(conf_get_str(conf,CONF_folder), "") && strcmp(conf_get_str(conf,CONF_folder),"Default") ) { cl = realloc( cl, 20 + strlen(conf_get_str(conf,CONF_folder)) ) ; @@ -3650,11 +3650,11 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation lp_eventlog(default_logpolicy, "----- Session restarted -----"); term_pwron(term, false); -#ifdef PERSOPORT -#ifdef PORTKNOCKINGPORT +#ifdef MOD_PERSO +#ifdef MOD_PORTKNOCKING ManagePortKnocking(conf_get_str(conf,CONF_host),conf_get_str(conf,CONF_portknockingoptions)); #endif -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT SetNewIcon( hwnd, conf_get_filename(conf,CONF_iconefile)->path, 0, SI_INIT ) ; is_backend_connected = 0 ; start_backend(); @@ -3686,7 +3686,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation break; else reconfiguring = true; -#ifndef PERSOPORT +#ifndef MOD_PERSO char buftitle[1024] = "" ; GetWindowText(hwnd, buftitle, sizeof(buftitle)); conf_set_str( conf, CONF_wintitle, buftitle ) ; @@ -3701,7 +3701,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation conf_set_str(conf, CONF_wintitle, window_name); prev_conf = conf_copy(conf); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( force_reconf++ ) { reconfig_result = do_reconfig(hwnd, backend ? backend_cfg_info(backend) : 0); @@ -3724,7 +3724,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation break; } #endif -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) if( GetBackgroundImageFlag() && (!GetPuttyFlag()) ) { if(textdc) { DeleteObject(textbm); @@ -3761,7 +3761,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation /* Gracefully unzoom if necessary */ if (IsZoomed(hwnd) && (resize_action == RESIZE_DISABLED)) ShowWindow(hwnd, SW_RESTORE); -#ifdef TUTTYPORT +#ifdef MOD_TUTTY HMENU m = GetSystemMenu (hwnd, FALSE); EnableMenuItem(m, SC_CLOSE, conf_get_int(conf,CONF_window_closable) ? MF_ENABLED : MF_GRAYED); #endif @@ -3794,7 +3794,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation /* Pass new config data to the back end */ if (backend) backend_reconfig(backend, conf); -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK /* * HACK: PuttyTray / Nutty * Reconfigure @@ -3863,7 +3863,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation else nflg |= WS_THICKFRAME; -#ifdef TUTTYPORT +#ifdef MOD_TUTTY if (!conf_get_int(conf,CONF_window_has_sysmenu)) nflg &= ~WS_SYSMENU; else @@ -3934,7 +3934,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation InvalidateRect(hwnd, NULL, true); reset_window(init_lvl); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( GetIconeFlag() != -1 ) { SetNewIcon( hwnd, conf_get_filename(conf,CONF_iconefile)->path, conf_get_int(conf,CONF_icone), SI_INIT ) ; } @@ -3958,7 +3958,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation term_request_copy(term, clips_system, lenof(clips_system)); break; case IDM_PASTE: -#ifdef PERSOPORT +#ifdef MOD_PERSO if( !GetProtectFlag() ) #endif term_request_paste(term, CLIP_SYSTEM); @@ -3975,7 +3975,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation showabout(hwnd); break; /* rutty: */ -#ifdef RUTTYPORT +#ifdef MOD_RUTTY case IDM_SCRIPTHALT: script_close(&scriptdata); lp_eventlog(default_logpolicy, "script stopped"); @@ -3994,7 +3994,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation } break; #endif /* rutty */ -#ifdef PERSOPORT +#ifdef MOD_PERSO /*case IDM_USERCMD: ManageSpecialCommand( hwnd, wParam-IDM_USERCMD ) ; break ;*/ @@ -4021,7 +4021,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation } } break ; -#ifdef LAUNCHERPORT +#ifdef MOD_LAUNCHER case IDM_HIDE: if( GetVisibleFlag()==VISIBLE_YES ) { /*if (IsWindowVisible(hwnd) )*/ ShowWindow(hwnd, SW_HIDE) ; @@ -4048,7 +4048,6 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation case IDM_WINROL: if( GetWinrolFlag() ) { ManageWinrol( hwnd, conf_get_int(conf,CONF_resize_action) ) ; - RefreshBackground( hwnd ) ; } break ; case IDM_SCRIPTFILE : @@ -4083,7 +4082,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation logfile_reinit(logctx); } break; -#ifdef PORTKNOCKINGPORT +#ifdef MOD_PORTKNOCKING case IDM_PORTKNOCK: ManagePortKnocking(conf_get_str(conf,CONF_host),conf_get_str(conf,CONF_portknockingoptions)); break; @@ -4091,7 +4090,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation case IDM_SHOWPORTFWD: ShowPortfwd( hwnd, conf ) ; break ; -#ifndef NO_TRANSPARENCY +#ifndef MOD_NOTRANSPARENCY case IDM_TRANSPARUP: // Augmenter l'opacite (diminuer la transparence) if( GetTransparencyFlag() && conf_get_int(conf,CONF_transparencynumber) > 0 ) { conf_set_int( conf, CONF_transparencynumber, conf_get_int(conf,CONF_transparencynumber)-10 ) ; @@ -4130,7 +4129,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation } break ; #endif -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT case IDM_RESTARTSESSION: // Redemarre une session en cours RestartSession() ; break ; @@ -4162,7 +4161,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation case IDM_FULLSCREEN: flip_full_screen(); break; -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM case IDM_XYZSTART: if( (!GetPuttyFlag()) && GetZModemFlag() ) { xyz_ReceiveInit(term); @@ -4199,7 +4198,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation } } break; -#ifdef PERSOPORT +#ifdef MOD_PERSO case WM_DROPFILES: { OnDropFiles(hwnd, (HDROP) wParam); } @@ -4251,7 +4250,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation break ; #endif -#ifdef WTSPORT +#ifdef MOD_WTS case WM_WTSSESSION_CHANGE: if( wParam == WTS_SESSION_UNLOCK ) { RefreshBackground(hwnd); @@ -4267,7 +4266,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation case WM_LBUTTONDOWN: case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT if( ((!backend) || (!is_backend_connected)) && GetAutoreconnectFlag() && is_backend_first_connected ) { // On essaie de se reconnecter PostMessage( hwnd, WM_COMMAND, IDM_RESTART, 0 ) ; lp_eventlog(default_logpolicy, "No connection on mouse click, trying to reconnect...") ; @@ -4277,7 +4276,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation case WM_LBUTTONUP: case WM_MBUTTONUP: case WM_RBUTTONUP: -#ifdef PERSOPORT +#ifdef MOD_PERSO if( GetProtectFlag() ) { break ; } if(!PuttyFlag && GetMouseShortcutsFlag() ) { if( (message == WM_LBUTTONUP) && ((wParam & MK_SHIFT)&&(wParam & MK_CONTROL) ) ) { // shift + CTRL + bouton gauche => duplicate session @@ -4285,7 +4284,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation lp_eventlog(default_logpolicy, "Duplicate session") ; SendMessage( hwnd, WM_COMMAND, IDM_DUPSESS, 0 ) ; } -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT else { if( is_backend_first_connected && GetAutoreconnectFlag() ) { SendMessage( hwnd, WM_COMMAND, IDM_RESTART, 0 ) ; @@ -4341,7 +4340,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation press = true; break; case WM_RBUTTONDOWN: -#ifdef PERSOPORT +#ifdef MOD_PERSO if( !GetProtectFlag() ) { button = MBT_RIGHT ; wParam |= MK_RBUTTON ; press = true ; } #else button = MBT_RIGHT; @@ -4360,7 +4359,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation press = false; break; case WM_RBUTTONUP: -#ifdef PERSOPORT +#ifdef MOD_PERSO if( !GetProtectFlag() ) { button = MBT_RIGHT ; wParam &= ~MK_RBUTTON ; press = false ; } #else button = MBT_RIGHT; @@ -4451,7 +4450,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation * number noise. */ noise_ultralight(NOISE_SOURCE_MOUSEPOS, lParam); -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK if( !GetPuttyFlag() && GetHyperlinkFlag() ) { /* * HACK: PuttyTray / Nutty @@ -4526,7 +4525,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation case WM_PAINT: { PAINTSTRUCT p; -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) HDC hdccod=0, hdcScreen, hdcBack = 0; if( GetBackgroundImageFlag() && (!GetPuttyFlag()) ) { HideCaret(hwnd); @@ -4597,7 +4596,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation */ //assert(!wintw_hdc); wintw_hdc = hdc; -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) if( GetBackgroundImageFlag() && (!GetPuttyFlag()) ) { term_paint(term, (p.rcPaint.left-offset_width)/font_width, @@ -4684,7 +4683,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation SelectObject(hdc, GetStockObject(WHITE_PEN)); EndPaint(hwnd, &p); ShowCaret(hwnd); -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) } #endif } @@ -4706,7 +4705,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation } return 0; case WM_SETFOCUS: -#ifdef PERSOPORT +#ifdef MOD_PERSO if( GetTransparencyFlag() && conf_get_int(conf,CONF_transparencynumber) >= 0 ) { SetTransparency( hwnd, 255-conf_get_int(conf,CONF_transparencynumber) ) ; } //RefreshBackground( hwnd ) ; @@ -4730,7 +4729,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation debug("WM_ENTERSIZEMOVE\n"); #endif EnableSizeTip(true); -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) if( GetBackgroundImageFlag() && (!PuttyFlag) ) GetClientRect(hwnd, &size_before); #endif resizing = true; @@ -4746,7 +4745,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation term_size(term, conf_get_int(conf, CONF_height), conf_get_int(conf, CONF_width), conf_get_int(conf, CONF_savelines)); -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) if( GetBackgroundImageFlag() && (conf_get_int(conf,CONF_bg_image_abs_fixed)==1) && (conf_get_int(conf,CONF_bg_type)!=0) ) RefreshBackground( hwnd ) ; #endif InvalidateRect(hwnd, NULL, true); @@ -4848,8 +4847,8 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation case WM_FULLSCR_ON_MAX: fullscr_on_max = true; break; -#ifdef PERSOPORT -#if (defined IMAGEPORT) && (!defined FDJ) +#ifdef MOD_PERSO +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) case WM_DISPLAYCHANGE: if( (!GetBackgroundImageFlag()) || GetPuttyFlag() ) return DefWindowProc(hwnd, message, wParam, lParam) ; case WM_MOVE: @@ -4929,7 +4928,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation LOWORD(lParam), HIWORD(lParam)); #endif -#ifdef PERSOPORT +#ifdef MOD_PERSO if (wParam == SIZE_MINIMIZED) { if( GetKeyState( VK_CONTROL ) & 0x8000 ) { SendMessage( hwnd, WM_COMMAND, IDM_TOTRAY, 0 ) ; return 0 ; @@ -4986,7 +4985,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation width = LOWORD(lParam); height = HIWORD(lParam); - if (wParam == SIZE_MAXIMIZED && !was_zoomed) { + if (wParam == SIZE_MAXIMIZED) { was_zoomed = true; prev_rows = term->rows; prev_cols = term->cols; @@ -5037,7 +5036,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation if (h < 1) h = 1; if (resizing) { -#ifdef PERSOPORT +#ifdef MOD_PERSO SetWinHeight( -1 ) ; #endif /* @@ -5056,11 +5055,11 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation reset_window(0); } } -#ifdef PERSOPORT +#ifdef MOD_PERSO if( GetTitleBarFlag() ) wintw_set_title( NULL, conf_get_str(conf,CONF_wintitle) ) ; // Pour refaire la barre de titre si option SizeFlag if( conf_get_bool(conf,CONF_saveonexit) ) GetWindowCoord( hwnd ) ; #endif -#ifdef IMAGEPORT +#ifdef MOD_BACKGROUNDIMAGE /* if( ((wParam == SIZE_RESTORED)&&(resizing!=TRUE)) || (wParam == SIZE_MAXIMIZED) ) { if( GetBackgroundImageFlag() && (conf_get_int(conf,CONF_bg_image_abs_fixed)==1) && (conf_get_int(conf,CONF_bg_type)!=0) ) RefreshBackground( hwnd ) ; @@ -5130,7 +5129,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation } } return false; -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK /* * HACK: PuttyTray / Nutty * Hyperlink stuff: Change cursor if we are in ctrl+click link mode @@ -5166,7 +5165,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation case WM_KEYUP: case WM_SYSKEYUP: #endif -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT //if( !back && GetAutoreconnectFlag() && is_backend_first_connected && (WM_COMMAND==WM_KEYDOWN) && !(GetKeyState(VK_CONTROL)&0x8000) && !(GetKeyState(VK_SHIFT)&0x8000) && !(GetKeyState(VK_MENU)&0x8000) && (wParam!=VK_TAB) && (wParam!=VK_LEFT) && (wParam!=VK_UP) && (wParam!=VK_RIGHT) && (wParam!=VK_DOWN) && !((wParam>=VK_F1)&&(wParam<=VK_F16)) ) { if( (!backend || !is_backend_connected) && (message==WM_KEYDOWN) && GetAutoreconnectFlag() && is_backend_first_connected && (wParam!=VK_CONTROL) && (wParam!=VK_SHIFT) && (wParam!=VK_MENU) && (wParam!=VK_TAB) && (wParam!=VK_LEFT) && (wParam!=VK_UP) && (wParam!=VK_RIGHT) && (wParam!=VK_DOWN) && !((wParam>=VK_F1)&&(wParam<=VK_F16)) ) { lp_eventlog(default_logpolicy, "No connection on key pressed, trying to reconnect...") ; @@ -5174,7 +5173,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation break ; } #endif -#ifdef PERSOPORT +#ifdef MOD_PERSO if( (wParam == VK_TAB) && (GetKeyState(VK_CONTROL) & 0x8000) ) { if( (message==WM_KEYUP) && conf_get_int(conf, CONF_ctrl_tab_switch) && GetCtrlTabFlag() ) { @@ -5194,11 +5193,11 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation AntiIdleCount = 0 ; /* Permet de sauvegarder tous les caracteres tapes au clavier pour les avoir dans le /savedump */ -#ifdef SAVEDUMPPORT +#ifdef MOD_SAVEDUMP if( debug_flag ) addkeypressed( message, wParam, lParam, GetKeyState(VK_SHIFT)&0x8000, GetKeyState(VK_CONTROL)&0x8000, (GetKeyState(VK_MENU)&0x8000)||(GetKeyState(VK_LMENU)&0x8000),GetKeyState(VK_RMENU)&0x8000, (GetKeyState(VK_RWIN)&0x8000)||(GetKeyState(VK_LWIN)&0x8000 ) ); #endif -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) if( (wParam==VK_SNAPSHOT)&&(GetKeyState(VK_CONTROL)&0x8000) ) { char screenShotFile[1024] ; sprintf( screenShotFile, "%s\\screenshot-%d-%ld.jpg", InitialDirectory, getpid(), time(0) ); @@ -5401,7 +5400,7 @@ else if((UINT_PTR)wParam == TIMER_LOGROTATION) { // log rotation case WM_GOT_CLIPDATA: process_clipdata((HGLOBAL)lParam, wParam); return 0; -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT case WM_POWERBROADCAST: if( GetAutoreconnectFlag() && conf_get_int(conf,CONF_wakeup_reconnect) && is_backend_first_connected) { switch(wParam) { @@ -5582,7 +5581,7 @@ static void do_text_internal( static size_t lpDx_len = 0; int *lpDx_maybe; int len2; /* for SURROGATE PAIR */ -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) int transBg = backgrounddc ? 1 : 0; UINT etoFlagOpaque = transBg ? 0 : ETO_OPAQUE; #endif @@ -5610,7 +5609,7 @@ static void do_text_internal( attr |= (260 << ATTR_FGSHIFT) | (261 << ATTR_BGSHIFT); is_cursor = true; } -#ifdef TUTTYPORT +#ifdef MOD_TUTTY if (!conf_get_int(conf,CONF_sel_colour) && (attr & ATTR_SELECTED)) { attr &= ~ATTR_SELECTED; attr |= ATTR_REVERSE; @@ -5678,7 +5677,7 @@ static void do_text_internal( nbg = ((attr & ATTR_BGMASK) >> ATTR_BGSHIFT); if (bold_font_mode == BOLD_FONT && (attr & ATTR_BOLD)) nfont |= FONT_BOLD; -#ifdef PERSOPORT +#ifdef MOD_PERSO if (attr & ATTR_ITALIC) nfont |= FONT_ITALIC; #endif @@ -5714,7 +5713,7 @@ static void do_text_internal( if (nbg < 16) nbg |= 8; else if (nbg >= 256) nbg |= 1; } -#ifdef TUTTYPORT +#ifdef MOD_TUTTY /* * quick & dirty hack: underlined text has colour preference over bold & normal * another one: selected text have absolute preference over all other attributes @@ -5778,7 +5777,7 @@ static void do_text_internal( GetGValue(fg) * 2 / 3, GetBValue(fg) * 2 / 3); } -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) HDC hdc = wintw_hdc ; if( GetBackgroundImageFlag() && (!GetPuttyFlag()) ) { line_box.left = x; @@ -5965,7 +5964,7 @@ static void do_text_internal( } if (nlen <= 0) return; /* Eeek! */ -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) if( GetBackgroundImageFlag() && (!GetPuttyFlag()) ) // ExtTextOutW(hdc, x, // y - font_height * (lattr == LATTR_BOT) + text_adjust, @@ -5998,7 +5997,7 @@ static void do_text_internal( sgrowarray(directbuf, directlen, len); for (size_t i = 0; i < len; i++) directbuf[i] = text[i] & 0xFF; -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) if( GetBackgroundImageFlag() && (!GetPuttyFlag()) ) // ExtTextOut(hdc, x, // y - font_height * (lattr == LATTR_BOT) + text_adjust, @@ -6044,7 +6043,7 @@ static void do_text_internal( for (i = 0; i < len; i++) wbuf[i] = text[i]; -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) /* print Glyphs as they are, without Windows' Shaping*/ if( GetBackgroundImageFlag() && (!PuttyFlag) ) // exact_textout(hdc, x, y - font_height * (lattr == LATTR_BOT) + text_adjust, @@ -6092,7 +6091,7 @@ static void do_text_internal( oldpen = SelectObject(wintw_hdc, oldpen); DeleteObject(oldpen); } -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) if( GetBackgroundImageFlag() && (!PuttyFlag) ) if(textdc) { @@ -6426,7 +6425,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, keystate[VK_RMENU] = keystate[VK_MENU]; } -#ifdef DISABLEALTGRPORT +#ifdef MOD_DISABLEALTGR /*disable altgr*/ if( !get_param("PUTTY") && conf_get_int(conf, CONF_disablealtgr) ) { keystate[VK_RMENU] = 0; @@ -6551,7 +6550,7 @@ if( !get_param("PUTTY") && conf_get_int(conf, CONF_disablealtgr) ) { /* If a key is pressed and AltGr is not active */ if (key_down && (keystate[VK_RMENU] & 0x80) == 0 && !compose_state) { /* Okay, prepare for most alts then ... */ -#ifdef KEYMAPPINGPORT +#ifdef MOD_KEYMAPPING if( !GetPuttyFlag() ) { if (left_alt && shift_state != 1 && !(wParam == VK_UP || wParam == VK_DOWN || wParam == VK_RIGHT || wParam == VK_LEFT)) *p++ = '\033'; @@ -6667,7 +6666,7 @@ if( !get_param("PUTTY") && conf_get_int(conf, CONF_disablealtgr) ) { *p++ = 0; return -2; } -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM if (wParam == VK_BACK && shift_state != 0) { /* Shift-Backspace, Ctrl-Backspace */ #else if (wParam == VK_BACK && shift_state == 1) { /* Shift Backspace */ @@ -6677,7 +6676,7 @@ if( !get_param("PUTTY") && conf_get_int(conf, CONF_disablealtgr) ) { *p++ = 0; return -2; } -#ifdef KEYMAPPINGPORT +#ifdef MOD_KEYMAPPING if( !GetPuttyFlag() ) { if (wParam == VK_TAB && shift_state == 2) { /* Ctrl-Tab */ p += sprintf((char *) p, "\x1B[27;5;9~"); @@ -6690,7 +6689,7 @@ if( !get_param("PUTTY") && conf_get_int(conf, CONF_disablealtgr) ) { } #endif if (wParam == VK_TAB && shift_state == 1) { /* Shift tab */ -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM p = output; /* don't also pass escape */ #endif *p++ = 0x1B; @@ -6703,7 +6702,7 @@ if( !get_param("PUTTY") && conf_get_int(conf, CONF_disablealtgr) ) { return p - output; } if (wParam == VK_SPACE && shift_state == 3) { /* Ctrl-Shift-Space */ -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM p = output; /* don't also pass escape */ *p++ = 160; /* Latin1 NBSP */ return p - output; @@ -6742,7 +6741,7 @@ if( !get_param("PUTTY") && conf_get_int(conf, CONF_disablealtgr) ) { *p++ = 0x1E; /* Ctrl-~ == Ctrl-^ in xterm at least */ return p - output; } -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM if (wParam == VK_RETURN && shift_state != 0) { /* Shift-Return, Ctrl-Return */ /* send LINEFEED */ *p++ = 012; @@ -6858,7 +6857,7 @@ if( !get_param("PUTTY") && conf_get_int(conf, CONF_disablealtgr) ) { case VK_LEFT: xkey = 'D'; goto arrow_key; case VK_CLEAR: xkey = 'G'; goto arrow_key; /* close enough */ arrow_key: -#ifdef KEYMAPPINGPORT +#ifdef MOD_KEYMAPPING p += format_arrow_key((char*)p, term, xkey, shift_state, left_alt); #else p += format_arrow_key((char *)p, term, xkey, shift_state & 2); @@ -6877,6 +6876,9 @@ if( !get_param("PUTTY") && conf_get_int(conf, CONF_disablealtgr) ) { return p - output; } else { *p++ = 0x0D; +#ifdef MOD_PERSO + if (conf_get_int(conf, CONF_enter_sends_crlf)) *p++ = 0x0A; +#endif *p++ = 0; return -2; } @@ -7001,7 +7003,7 @@ if( !get_param("PUTTY") && conf_get_int(conf, CONF_disablealtgr) ) { } else { WCHAR cbuf[2]; cbuf[0] = '\033'; -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM cbuf[1] = wch | ((left_alt & conf_get_int(conf,CONF_alt_metabit)) << 7); term_keyinputw(term, cbuf + !(left_alt & !conf_get_int(conf,CONF_alt_metabit)), 1 + !!(left_alt & !conf_get_int(conf,CONF_alt_metabit)) ); #else @@ -7039,7 +7041,7 @@ if( !get_param("PUTTY") && conf_get_int(conf, CONF_disablealtgr) ) { return -1; } -#ifdef PERSOPORT +#ifdef MOD_PERSO void set_title_internal(TermWin *tw, const char *title) { sfree(window_name); @@ -7080,7 +7082,7 @@ void make_title( char * res, char * fmt, const char * title ) { case PROT_TELNET: strcpy(b,"telnet"); if(port==-1) port=23 ; break; case PROT_RLOGIN: strcpy(b,"rlogin"); break; case PROT_SSH: strcpy(b,"ssh"); if(port==-1) port=22 ; break; -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM case PROT_CYGTERM: strcpy(b,"cyg"); break; #endif case PROT_SERIAL: strcpy(b,"serial"); break; @@ -7127,7 +7129,7 @@ static void wintw_set_title(TermWin *tw, const char *title_in) { if( strstr(title, " (PROTECTED)")==(title+strlen(title)-12) ) { title[strlen(title)-12]='\0' ; } -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) buffer = (char*) malloc( strlen( title ) + strlen( conf_get_str(conf,CONF_host)) + strlen( conf_get_filename(conf,CONF_bg_image_filename)->path ) + 40 ) ; if( GetBackgroundImageFlag() && GetImageViewerFlag() && (!PuttyFlag) ) { sprintf( buffer, "%s", conf_get_filename(conf,CONF_bg_image_filename)->path ) ; } else @@ -7899,7 +7901,7 @@ static void flash_window_timer(void *ctx, unsigned long now) */ static void flash_window(int mode) { -#ifdef PERSOPORT +#ifdef MOD_PERSO static int BlinkingState = 0 ; if(MaxBlinkingTime && (mode!=0)) { if( BlinkingState>=MaxBlinkingTime ) { @@ -7934,7 +7936,7 @@ static void flash_window(int mode) * uCount=0 appears to enable continuous flashing, per * "flashing" mode, although I haven't seen this * documented. */ -#ifdef PERSOPORT +#ifdef MOD_PERSO flash_window_ex(FLASHW_ALL | FLASHW_TIMER, MaxBlinkingTime, 0 /* system cursor blink rate */); @@ -8017,7 +8019,7 @@ static void wintw_bell(TermWin *tw, int mode) } /* Otherwise, either visual bell or disabled; do nothing here */ if (!term->has_focus) { -#ifdef PERSOPORT +#ifdef MOD_PERSO if( GetVisibleFlag()!=VISIBLE_TRAY ) { if(conf_get_bool(conf,CONF_foreground_on_bell) ) { // Tester avec sleep 4 ; echo -e '\a' if( IsIconic(hwnd) ) SwitchToThisWindow( hwnd, TRUE ) ; @@ -8272,16 +8274,16 @@ static void flip_full_screen() SendMessage(hwnd, WM_FULLSCR_ON_MAX, 0, 0); ShowWindow(hwnd, SW_MAXIMIZE); } -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) if( GetBackgroundImageFlag()&&(!PuttyFlag)&&(conf_get_int(conf,CONF_bg_image_abs_fixed)==1)&&(conf_get_int(conf,CONF_bg_type)!=0) ) RefreshBackground( hwnd ) ; #endif } -#ifdef PERSOPORT +#ifdef MOD_PERSO /* rutty: special entry point for ldisc.c - local backend modified version for all other backends */ -#ifdef RUTTYPORT +#ifdef MOD_RUTTY size_t win_seat_output_local(Seat *seat, bool is_stderr, const void *data, size_t len) { int res = term_data(term, is_stderr, data, len) ; @@ -8297,7 +8299,7 @@ static size_t win_seat_output(Seat *seat, bool is_stderr, const void *data, size return res ; } #else -/* Version avec PERSOPORT seule sans RUTTYPORT */ +/* Version avec MOD_PERSO seule sans MOD_RUTTY */ static size_t win_seat_output(Seat *seat, bool is_stderr, const void *data, size_t len) { int res = term_data(term, is_stderr, data, len) ; diff --git a/0.72_My_PuTTY/windows/wingss.c b/0.73_My_PuTTY/windows/wingss.c similarity index 100% rename from 0.72_My_PuTTY/windows/wingss.c rename to 0.73_My_PuTTY/windows/wingss.c diff --git a/0.72_My_PuTTY/windows/winhandl.c b/0.73_My_PuTTY/windows/winhandl.c similarity index 100% rename from 0.72_My_PuTTY/windows/winhandl.c rename to 0.73_My_PuTTY/windows/winhandl.c diff --git a/0.72_My_PuTTY/windows/winhelp.c b/0.73_My_PuTTY/windows/winhelp.c similarity index 99% rename from 0.72_My_PuTTY/windows/winhelp.c rename to 0.73_My_PuTTY/windows/winhelp.c index 769629b..521dda2 100644 --- a/0.72_My_PuTTY/windows/winhelp.c +++ b/0.73_My_PuTTY/windows/winhelp.c @@ -18,7 +18,7 @@ void init_help(void) { } void shutdown_help(void) { } void launch_help(HWND hwnd, const char *topic) { } void quit_help(HWND hwnd) { } -#ifdef PERSOPORT +#ifdef MOD_PERSO int has_embedded_chm(void) { return 0 ; } #endif #else diff --git a/0.72_My_PuTTY/windows/winhelp.h b/0.73_My_PuTTY/windows/winhelp.h similarity index 100% rename from 0.72_My_PuTTY/windows/winhelp.h rename to 0.73_My_PuTTY/windows/winhelp.h diff --git a/0.72_My_PuTTY/windows/winhelp.rc2 b/0.73_My_PuTTY/windows/winhelp.rc2 similarity index 100% rename from 0.72_My_PuTTY/windows/winhelp.rc2 rename to 0.73_My_PuTTY/windows/winhelp.rc2 diff --git a/0.72_My_PuTTY/windows/winhsock.c b/0.73_My_PuTTY/windows/winhsock.c similarity index 98% rename from 0.72_My_PuTTY/windows/winhsock.c rename to 0.73_My_PuTTY/windows/winhsock.c index 7f2b447..aa3b5a9 100644 --- a/0.72_My_PuTTY/windows/winhsock.c +++ b/0.73_My_PuTTY/windows/winhsock.c @@ -156,12 +156,6 @@ static void sk_handle_write_eof(Socket *s) handle_write_eof(hs->send_h); } -static void sk_handle_flush(Socket *s) -{ - /* HandleSocket *hs = container_of(s, HandleSocket, sock); */ - /* do nothing */ -} - static void handle_socket_unfreeze(void *hsv) { HandleSocket *hs = (HandleSocket *)hsv; @@ -315,7 +309,6 @@ static const SocketVtable HandleSocket_sockvt = { sk_handle_write, sk_handle_write_oob, sk_handle_write_eof, - sk_handle_flush, sk_handle_set_frozen, sk_handle_socket_error, sk_handle_peer_info, diff --git a/0.72_My_PuTTY/windows/winjump.c b/0.73_My_PuTTY/windows/winjump.c similarity index 99% rename from 0.72_My_PuTTY/windows/winjump.c rename to 0.73_My_PuTTY/windows/winjump.c index 9d0534c..a6eab7b 100644 --- a/0.72_My_PuTTY/windows/winjump.c +++ b/0.73_My_PuTTY/windows/winjump.c @@ -736,7 +736,7 @@ bool set_explicit_app_user_model_id(void) if (p_SetCurrentProcessExplicitAppUserModelID) { -#ifdef PERSOPORT +#ifdef MOD_PERSO if (p_SetCurrentProcessExplicitAppUserModelID(L"9bis.com.KiTTY") == S_OK) #else if (p_SetCurrentProcessExplicitAppUserModelID(L"SimonTatham.PuTTY") == S_OK) diff --git a/0.72_My_PuTTY/windows/winmisc.c b/0.73_My_PuTTY/windows/winmisc.c similarity index 100% rename from 0.72_My_PuTTY/windows/winmisc.c rename to 0.73_My_PuTTY/windows/winmisc.c diff --git a/0.72_My_PuTTY/windows/winmiscs.c b/0.73_My_PuTTY/windows/winmiscs.c similarity index 100% rename from 0.72_My_PuTTY/windows/winmiscs.c rename to 0.73_My_PuTTY/windows/winmiscs.c diff --git a/0.72_My_PuTTY/windows/winnet.c b/0.73_My_PuTTY/windows/winnet.c similarity index 98% rename from 0.72_My_PuTTY/windows/winnet.c rename to 0.73_My_PuTTY/windows/winnet.c index 60231c5..14cbdc6 100644 --- a/0.72_My_PuTTY/windows/winnet.c +++ b/0.73_My_PuTTY/windows/winnet.c @@ -54,7 +54,7 @@ struct NetSocket { Plug *plug; bufchain output_data; bool connected; -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM int closing; /* used when closing the connection, while we flush the remaining items */ #endif bool writable; @@ -124,18 +124,18 @@ struct SockAddr { static tree234 *sktree; -#ifdef PERSOPORT +#ifdef MOD_PERSO #include "kitty.h" int get_param( const char * val ) ; #endif -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM static int curpass; #endif static int cmpfortree(void *av, void *bv) { NetSocket *a = (NetSocket *)av, *b = (NetSocket *)bv; - unsigned long as = (unsigned long) a->s, bs = (unsigned long) b->s; + uintptr_t as = (uintptr_t) a->s, bs = (uintptr_t) b->s; if (as < bs) return -1; if (as > bs) @@ -195,7 +195,7 @@ DECL_WINDOWS_FUNCTION(static, int, WSAIoctl, (SOCKET, DWORD, LPVOID, DWORD, LPVOID, DWORD, LPDWORD, LPWSAOVERLAPPED, LPWSAOVERLAPPED_COMPLETION_ROUTINE)); -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM DECL_WINDOWS_FUNCTION(static, int, getsockname, (SOCKET, const struct sockaddr FAR *, int FAR *)); #endif @@ -333,7 +333,7 @@ void sk_init(void) GET_WINDOWS_FUNCTION(winsock_module, getpeername); GET_WINDOWS_FUNCTION(winsock_module, recv); GET_WINDOWS_FUNCTION(winsock_module, WSAIoctl); -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM GET_WINDOWS_FUNCTION(winsock_module, getsockname); #endif @@ -345,7 +345,7 @@ void sk_init(void) } sktree = newtree234(cmpfortree); -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM if( (!GetPuttyFlag()) && GetZModemFlag() ) { curpass = 1; } @@ -847,14 +847,6 @@ static Plug *sk_net_plug(Socket *sock, Plug *p) return ret; } -static void sk_net_flush(Socket *s) -{ - /* - * We send data to the socket as soon as we can anyway, - * so we don't need to do anything here. :-) - */ -} - static void sk_net_close(Socket *s); static size_t sk_net_write(Socket *s, const void *data, size_t len); static size_t sk_net_write_oob(Socket *s, const void *data, size_t len); @@ -869,13 +861,12 @@ static const SocketVtable NetSocket_sockvt = { sk_net_write, sk_net_write_oob, sk_net_write_eof, - sk_net_flush, sk_net_set_frozen, sk_net_socket_error, sk_net_peer_info, }; -#ifdef PERSOPORT +#ifdef MOD_PERSO Socket sk_register(void *sock, Plug *plug) { DWORD err; @@ -890,7 +881,7 @@ Socket sk_register(void *sock, Plug *plug) ret->error = NULL; ret->plug = plug; bufchain_init(&ret->output_data); -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM if( (!GetPuttyFlag()) && GetZModemFlag() ) { ret->closing = 0; } @@ -929,7 +920,7 @@ Socket sk_register(void *sock, Plug *plug) } #endif -#ifdef PERSOPORT +#ifdef MOD_PERSO Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug) #else static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug) @@ -947,7 +938,7 @@ static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug) ret->error = NULL; ret->plug = plug; bufchain_init(&ret->output_data); -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM if( (!GetPuttyFlag()) && GetZModemFlag() ) { ret->closing = 0; } @@ -1001,7 +992,7 @@ static DWORD try_connect(NetSocket *sock) do_select(sock->s, false); p_closesocket(sock->s); } -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM if(!GetZModemFlag() || !sock->closing) { SockAddr thisaddr = sk_extractaddr_tmp( sock->addr, &sock->step); @@ -1180,7 +1171,7 @@ static DWORD try_connect(NetSocket *sock) * No matter what happened, put the socket back in the tree. */ add234(sktree, sock); -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM if( (!GetPuttyFlag()) && GetZModemFlag() ) { if( err && !sock->closing) { SockAddr thisaddr = sk_extractaddr_tmp( @@ -1220,7 +1211,7 @@ Socket *sk_new(SockAddr *addr, int port, bool privport, bool oobinline, ret->plug = plug; bufchain_init(&ret->output_data); ret->connected = false; /* to start with */ -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM if( (!GetPuttyFlag()) && GetZModemFlag() ) { ret->closing = 0; } @@ -1263,7 +1254,6 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, char *errstr; NetSocket *ret; int retcode; - int on = 1; int address_family; @@ -1275,7 +1265,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, ret->error = NULL; ret->plug = plug; bufchain_init(&ret->output_data); -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM if( (!GetPuttyFlag()) && GetZModemFlag() ) { ret->closing = 0; } @@ -1325,7 +1315,11 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, ret->oobinline = false; - p_setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on)); + { + BOOL on = true; + p_setsockopt(s, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, + (const char *)&on, sizeof(on)); + } #ifndef NO_IPV6 if (address_family == AF_INET6) { @@ -1449,7 +1443,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, return &ret->sock; } -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM int sk_getport(Socket *sock) { /* I won't even try to get IPv6 working here since it is apparently borken @@ -1469,7 +1463,7 @@ int sk_getport(Socket *sock) } #endif -#ifdef NO_ZMODEMPORT /* A partir de 0.64.0.3 on prend le code normal */ +#ifdef NO_MOD_ZMODEM /* A partir de 0.64.0.3 on prend le code normal */ static void sk_tcp_really_close(Actual_Socket s) { extern char *do_select(SOCKET skt, int startup); @@ -1709,7 +1703,7 @@ void select_result(WPARAM wParam, LPARAM lParam) * plug. */ if (s->addr) { -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM if( (!GetPuttyFlag()) && GetZModemFlag() ) { if (!s->closing) { SockAddr thisaddr = sk_extractaddr_tmp( @@ -1734,7 +1728,7 @@ void select_result(WPARAM wParam, LPARAM lParam) err = try_connect(s); } } -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM if( (!GetPuttyFlag()) && GetZModemFlag() ) { if (err != 0 && !s->closing) plug_closing(s->plug, winsock_error_string(err), err, 0); @@ -1803,7 +1797,7 @@ void select_result(WPARAM wParam, LPARAM lParam) break; } } -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM if( (!GetPuttyFlag()) && GetZModemFlag() &&0 ) { if( !s->closing ) { if (ret < 0) { @@ -1837,7 +1831,7 @@ void select_result(WPARAM wParam, LPARAM lParam) if (ret <= 0) { int err = p_WSAGetLastError(); plug_closing(s->plug, winsock_error_string(err), err, 0); -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM } else if( (!GetPuttyFlag()) && GetZModemFlag() && s->closing) { return ; #endif @@ -1852,7 +1846,7 @@ void select_result(WPARAM wParam, LPARAM lParam) bufsize_before = s->sending_oob + bufchain_size(&s->output_data); try_send(s); bufsize_after = s->sending_oob + bufchain_size(&s->output_data); -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM if( (!GetPuttyFlag()) && GetZModemFlag() ) { if (bufsize_after < bufsize_before && !s->closing) plug_sent(s->plug, bufsize_after); @@ -1871,12 +1865,12 @@ void select_result(WPARAM wParam, LPARAM lParam) err = p_WSAGetLastError(); if (err == WSAEWOULDBLOCK) break; -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM if( (!GetPuttyFlag()) && GetZModemFlag() && s->closing ) return ; #endif plug_closing(s->plug, winsock_error_string(err), err, 0); -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM } else if( (!GetPuttyFlag()) && GetZModemFlag() && s->closing) { #endif } else { @@ -1919,7 +1913,7 @@ void select_result(WPARAM wParam, LPARAM lParam) #endif { p_closesocket(t); /* dodgy WinSock let nonlocal through */ -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM } if( (!GetPuttyFlag()) && GetZModemFlag() ) { if (!s->closing && plug_accepting(s->plug, sk_net_accept, actx)) { @@ -1940,7 +1934,7 @@ void select_result(WPARAM wParam, LPARAM lParam) } } -#if (defined ZMODEMPORT) +#if (defined MOD_ZMODEM) struct netscheduler_tag { int interval; int pending; diff --git a/0.72_My_PuTTY/windows/winnohlp.c b/0.73_My_PuTTY/windows/winnohlp.c similarity index 100% rename from 0.72_My_PuTTY/windows/winnohlp.c rename to 0.73_My_PuTTY/windows/winnohlp.c diff --git a/0.72_My_PuTTY/windows/winnoise.c b/0.73_My_PuTTY/windows/winnoise.c similarity index 100% rename from 0.72_My_PuTTY/windows/winnoise.c rename to 0.73_My_PuTTY/windows/winnoise.c diff --git a/0.72_My_PuTTY/windows/winnojmp.c b/0.73_My_PuTTY/windows/winnojmp.c similarity index 100% rename from 0.72_My_PuTTY/windows/winnojmp.c rename to 0.73_My_PuTTY/windows/winnojmp.c diff --git a/0.72_My_PuTTY/windows/winnpc.c b/0.73_My_PuTTY/windows/winnpc.c similarity index 100% rename from 0.72_My_PuTTY/windows/winnpc.c rename to 0.73_My_PuTTY/windows/winnpc.c diff --git a/0.72_My_PuTTY/windows/winnps.c b/0.73_My_PuTTY/windows/winnps.c similarity index 99% rename from 0.72_My_PuTTY/windows/winnps.c rename to 0.73_My_PuTTY/windows/winnps.c index fa1d804..5c20164 100644 --- a/0.72_My_PuTTY/windows/winnps.c +++ b/0.73_My_PuTTY/windows/winnps.c @@ -192,7 +192,7 @@ static void named_pipe_connect_callback(void *vps) /* * This socket type is only used for listening, so it should never - * be asked to write or flush or set_frozen. + * be asked to write or set_frozen. */ static const SocketVtable NamedPipeServerSocket_sockvt = { sk_namedpipeserver_plug, @@ -200,7 +200,6 @@ static const SocketVtable NamedPipeServerSocket_sockvt = { NULL /* write */, NULL /* write_oob */, NULL /* write_eof */, - NULL /* flush */, NULL /* set_frozen */, sk_namedpipeserver_socket_error, sk_namedpipeserver_peer_info, diff --git a/0.72_My_PuTTY/windows/winpgen.c b/0.73_My_PuTTY/windows/winpgen.c similarity index 99% rename from 0.72_My_PuTTY/windows/winpgen.c rename to 0.73_My_PuTTY/windows/winpgen.c index cabef9f..a4bb671 100644 --- a/0.72_My_PuTTY/windows/winpgen.c +++ b/0.73_My_PuTTY/windows/winpgen.c @@ -27,7 +27,7 @@ static char *cmdline_keyfile = NULL; -#ifndef INTEGRATED_KEYGEN +#ifndef MOD_INTEGRATED_KEYGEN int GetZModemFlag() { return 0 ; } /* * Print a modal (Really Bad) message box and perform a fatal exit. @@ -316,7 +316,7 @@ static INT_PTR CALLBACK AboutProc(HWND hwnd, UINT msg, return 0; case 101: EnableWindow(hwnd, 0); -#ifdef INTEGRATED_KEYGEN +#ifdef MOD_INTEGRATED_KEYGEN DialogBox(hinst, MAKEINTRESOURCE(814), hwnd, LicenceProc); #else DialogBox(hinst, MAKEINTRESOURCE(214), hwnd, LicenceProc); @@ -428,7 +428,7 @@ static void setupbigedit2(HWND hwnd, int id, int idstatic, sfree(buffer); } -#ifndef INTEGRATED_KEYGEN +#ifndef MOD_INTEGRATED_KEYGEN /* * Warn about the obsolescent key file format. */ @@ -696,7 +696,7 @@ void load_key_file(HWND hwnd, struct MainDlgState *state, pps.passphrase = &passphrase; pps.comment = comment; dlgret = DialogBoxParam(hinst, -#ifdef INTEGRATED_KEYGEN +#ifdef MOD_INTEGRATED_KEYGEN MAKEINTRESOURCE(810), #else MAKEINTRESOURCE(210), @@ -878,7 +878,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, * if the help file isn't present. */ } -#ifdef INTEGRATED_KEYGEN +#ifdef MOD_INTEGRATED_KEYGEN SendMessage(hwnd, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) LoadIcon(hinst, MAKEINTRESOURCE(800))); #else @@ -1111,7 +1111,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, break; case IDC_ABOUT: EnableWindow(hwnd, 0); -#ifdef INTEGRATED_KEYGEN +#ifdef MOD_INTEGRATED_KEYGEN DialogBox(hinst, MAKEINTRESOURCE(813), hwnd, AboutProc); #else DialogBox(hinst, MAKEINTRESOURCE(213), hwnd, AboutProc); @@ -1570,7 +1570,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, return 0; } -#ifndef INTEGRATED_KEYGEN +#ifndef MOD_INTEGRATED_KEYGEN void cleanup_exit(int code) { shutdown_help(); diff --git a/0.72_My_PuTTY/windows/winpgnt.c b/0.73_My_PuTTY/windows/winpgnt.c similarity index 98% rename from 0.72_My_PuTTY/windows/winpgnt.c rename to 0.73_My_PuTTY/windows/winpgnt.c index 3dbfec0..2172056 100644 --- a/0.72_My_PuTTY/windows/winpgnt.c +++ b/0.73_My_PuTTY/windows/winpgnt.c @@ -21,7 +21,7 @@ #include -#ifdef PERSOPORT +#ifdef MOD_PERSO void scrumble_int(); // Flag pour le fonctionnement en mode "portable" (gestion par fichiers) extern int IniFileFlag ; @@ -41,7 +41,7 @@ extern int DirectoryBrowseFlag ; #endif #endif -#ifndef INTEGRATED_AGENT +#ifndef MOD_INTEGRATED_AGENT #define IDI_MAINICON 200 #define IDI_TRAYICON 201 #else @@ -65,7 +65,7 @@ extern int DirectoryBrowseFlag ; #define IDM_HELP 0x0040 #define IDM_ABOUT 0x0050 -#ifdef WINCRYPTPORT +#ifdef MOD_WINCRYPT #ifdef USE_CAPI #define IDM_ADDCERT 0x0070 #endif /* USE_CAPI */ @@ -91,7 +91,7 @@ static filereq *keypath = NULL; #define PUTTY_DEFAULT "Default%20Settings" static int initial_menuitems_count; -#ifndef INTEGRATED_AGENT +#ifndef MOD_INTEGRATED_AGENT /* * Print a modal (Really Bad) message box and perform a fatal exit. */ @@ -256,7 +256,7 @@ static INT_PTR CALLBACK PassphraseProc(HWND hwnd, UINT msg, return 0; } -#ifndef INTEGRATED_AGENT +#ifndef MOD_INTEGRATED_AGENT /* * Warn about the obsolescent key file format. */ @@ -444,7 +444,7 @@ static void win_add_keyfile(Filename *filename) } -#ifdef WINCRYPTPORT +#ifdef MOD_WINCRYPT #ifdef USE_CAPI /* * Add a key from a Windows certificate @@ -621,7 +621,7 @@ static INT_PTR CALLBACK KeyListProc(HWND hwnd, UINT msg, keylist = NULL; DestroyWindow(hwnd); return 0; -#ifdef WINCRYPTPORT +#ifdef MOD_WINCRYPT #ifdef USE_CAPI case 100: /* key list */ if(HIWORD(wParam) == LBN_DBLCLK) { @@ -751,7 +751,7 @@ static BOOL AddTrayIcon(HWND hwnd) tnid.uID = 1; /* unique within this systray use */ tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; tnid.uCallbackMessage = WM_SYSTRAY; -#ifndef INTEGRATED_AGENT +#ifndef MOD_INTEGRATED_AGENT tnid.hIcon = hicon = LoadIcon(hinst, MAKEINTRESOURCE(201)); strcpy(tnid.szTip, "Pageant (PuTTY authentication agent)"); #else @@ -761,7 +761,7 @@ static BOOL AddTrayIcon(HWND hwnd) res = Shell_NotifyIcon(NIM_ADD, &tnid); -#ifdef PERSOPORT +#ifdef MOD_PERSO trayIcone = tnid ; #endif @@ -1151,7 +1151,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, } prompt_add_keyfile(); break; -#ifdef WINCRYPTPORT +#ifdef MOD_WINCRYPT #ifdef USE_CAPI case IDM_ADDCERT: prompt_add_capikey(); @@ -1247,15 +1247,11 @@ void spawn_cmd(const char *cmdline, const char *args, int show) } } -#ifndef INTEGRATED_AGENT -/* - * This is a can't-happen stub, since Pageant never makes - * asynchronous agent requests. - */ +#ifndef MOD_INTEGRATED_AGENT void agent_schedule_callback(void (*callback)(void *, void *, int), void *callback_ctx, void *data, int len) { - assert(!"We shouldn't get here"); + unreachable("all Pageant's own agent requests should be synchronous"); } void cleanup_exit(int code) @@ -1268,7 +1264,7 @@ void cleanup_exit(int code) int flags = FLAG_SYNCAGENT; -#ifndef INTEGRATED_AGENT +#ifndef MOD_INTEGRATED_AGENT int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) #else int WINAPI Agent_WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) @@ -1286,7 +1282,7 @@ int WINAPI Agent_WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show hinst = inst; hwnd = NULL; -#ifdef PERSOPORT +#ifdef MOD_PERSO IniFileFlag = 0 ; DirectoryBrowseFlag = 0 ; LoadParametersLight() ; @@ -1342,7 +1338,7 @@ int WINAPI Agent_WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show if ( (fp = fopen(b, "r")) != NULL) { putty_path = dupstr(b); fclose(fp); -#ifdef PERSOPORT +#ifdef MOD_PERSO } else { strcpy(r, "kitty.exe"); if ( (fp = fopen(b, "r")) != NULL) { @@ -1472,7 +1468,7 @@ int WINAPI Agent_WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show AppendMenu(systray_menu, MF_ENABLED, IDM_VIEWKEYS, "&View Keys"); AppendMenu(systray_menu, MF_ENABLED, IDM_ADDKEY, "Add &Key"); -#ifdef WINCRYPTPORT +#ifdef MOD_WINCRYPT #ifdef USE_CAPI AppendMenu(systray_menu, MF_ENABLED, IDM_ADDCERT, "Add &Certificate"); #endif /* USE_CAPI */ diff --git a/0.72_My_PuTTY/windows/winpgntc.c b/0.73_My_PuTTY/windows/winpgntc.c similarity index 100% rename from 0.72_My_PuTTY/windows/winpgntc.c rename to 0.73_My_PuTTY/windows/winpgntc.c diff --git a/0.72_My_PuTTY/windows/winplink.c b/0.73_My_PuTTY/windows/winplink.c similarity index 97% rename from 0.72_My_PuTTY/windows/winplink.c rename to 0.73_My_PuTTY/windows/winplink.c index 23c70f1..c4f7232 100644 --- a/0.72_My_PuTTY/windows/winplink.c +++ b/0.73_My_PuTTY/windows/winplink.c @@ -13,7 +13,7 @@ #include "tree234.h" #include "winsecur.h" -#ifdef PERSOPORT +#ifdef MOD_PERSO // Flag pour le fonctionnement en mode "portable" (gestion par fichiers) extern int IniFileFlag ; @@ -49,7 +49,7 @@ void SetUsernameInConfig( char * username ) { } } #endif -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM void cygterm_set_flag( int flag ) { } #endif @@ -219,7 +219,7 @@ static void usage(void) printf(" log protocol details to a file\n"); printf(" -shareexists\n"); printf(" test whether a connection-sharing upstream exists\n"); -#ifdef PERSOPORT +#ifdef MOD_PERSO printf(" -auto-store-sshkey\n"); printf(" store automatically the servers ssh keys\n"); #endif @@ -303,11 +303,11 @@ const bool share_can_be_downstream = true; const bool share_can_be_upstream = true; -#ifdef PORTKNOCKINGPORT +#ifdef MOD_PORTKNOCKING int ManagePortKnocking( char* host, char *portknockseq ) ; #endif -#ifdef PERSOPORT +#ifdef MOD_PERSO char * AutoCommand = NULL ; void ManageAutocommand( struct handle *h ) { char c = '\n' ; @@ -354,7 +354,7 @@ int main(int argc, char **argv) { } #endif -#ifdef PERSOPORT +#ifdef MOD_PERSO int plink_main(int argc, char **argv) { LoadParametersLight() ; @@ -546,7 +546,7 @@ int main(int argc, char **argv) else return 1; } -#ifdef PORTKNOCKINGPORT +#ifdef MOD_PORTKNOCKING ManagePortKnocking(conf_get_str(conf,CONF_host),conf_get_str(conf,CONF_portknockingoptions)); #endif @@ -554,29 +554,6 @@ int main(int argc, char **argv) lp_eventlog(default_logpolicy, "Running with restricted process ACL"); } - /* - * Start up the connection. - */ - netevent = CreateEvent(NULL, false, false, NULL); - { - const char *error; - char *realhost; - /* nodelay is only useful if stdin is a character device (console) */ - bool nodelay = conf_get_bool(conf, CONF_tcp_nodelay) && - (GetFileType(GetStdHandle(STD_INPUT_HANDLE)) == FILE_TYPE_CHAR); - - error = backend_init(vt, plink_seat, &backend, logctx, conf, - conf_get_str(conf, CONF_host), - conf_get_int(conf, CONF_port), - &realhost, nodelay, - conf_get_bool(conf, CONF_tcp_keepalives)); - if (error) { - fprintf(stderr, "Unable to open connection:\n%s", error); - return 1; - } - sfree(realhost); - } - inhandle = GetStdHandle(STD_INPUT_HANDLE); outhandle = GetStdHandle(STD_OUTPUT_HANDLE); errhandle = GetStdHandle(STD_ERROR_HANDLE); @@ -628,6 +605,29 @@ int main(int argc, char **argv) stderr_bs = BinarySink_UPCAST(stderr_scc); } + /* + * Start up the connection. + */ + netevent = CreateEvent(NULL, false, false, NULL); + { + const char *error; + char *realhost; + /* nodelay is only useful if stdin is a character device (console) */ + bool nodelay = conf_get_bool(conf, CONF_tcp_nodelay) && + (GetFileType(GetStdHandle(STD_INPUT_HANDLE)) == FILE_TYPE_CHAR); + + error = backend_init(vt, plink_seat, &backend, logctx, conf, + conf_get_str(conf, CONF_host), + conf_get_int(conf, CONF_port), + &realhost, nodelay, + conf_get_bool(conf, CONF_tcp_keepalives)); + if (error) { + fprintf(stderr, "Unable to open connection:\n%s", error); + return 1; + } + sfree(realhost); + } + main_thread_id = GetCurrentThreadId(); sending = false; diff --git a/0.72_My_PuTTY/windows/winprint.c b/0.73_My_PuTTY/windows/winprint.c similarity index 100% rename from 0.72_My_PuTTY/windows/winprint.c rename to 0.73_My_PuTTY/windows/winprint.c diff --git a/0.72_My_PuTTY/windows/winproxy.c b/0.73_My_PuTTY/windows/winproxy.c similarity index 100% rename from 0.72_My_PuTTY/windows/winproxy.c rename to 0.73_My_PuTTY/windows/winproxy.c diff --git a/0.72_My_PuTTY/windows/winsecur.c b/0.73_My_PuTTY/windows/winsecur.c similarity index 100% rename from 0.72_My_PuTTY/windows/winsecur.c rename to 0.73_My_PuTTY/windows/winsecur.c diff --git a/0.72_My_PuTTY/windows/winsecur.h b/0.73_My_PuTTY/windows/winsecur.h similarity index 100% rename from 0.72_My_PuTTY/windows/winsecur.h rename to 0.73_My_PuTTY/windows/winsecur.h diff --git a/0.72_My_PuTTY/windows/winser.c b/0.73_My_PuTTY/windows/winser.c similarity index 100% rename from 0.72_My_PuTTY/windows/winser.c rename to 0.73_My_PuTTY/windows/winser.c diff --git a/0.72_My_PuTTY/windows/winsftp.c b/0.73_My_PuTTY/windows/winsftp.c similarity index 99% rename from 0.72_My_PuTTY/windows/winsftp.c rename to 0.73_My_PuTTY/windows/winsftp.c index 8912035..3859a7c 100644 --- a/0.72_My_PuTTY/windows/winsftp.c +++ b/0.73_My_PuTTY/windows/winsftp.c @@ -12,7 +12,7 @@ #include "ssh.h" #include "winsecur.h" -#ifdef PERSOPORT +#ifdef MOD_PERSO #include // Flag pour le fonctionnement en mode "portable" (gestion par fichiers) @@ -48,7 +48,7 @@ void SetUsernameInConfig( char * username ) { } } #endif -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM void cygterm_set_flag( int flag ) { } #endif @@ -795,7 +795,7 @@ void platform_psftp_pre_conn_setup(void) int main(int argc, char *argv[]) { int ret; -#ifdef PERSOPORT +#ifdef MOD_PERSO IniFileFlag = 0 ; DirectoryBrowseFlag = 0 ; LoadParametersLight() ; diff --git a/0.72_My_PuTTY/windows/winshare.c b/0.73_My_PuTTY/windows/winshare.c similarity index 100% rename from 0.72_My_PuTTY/windows/winshare.c rename to 0.73_My_PuTTY/windows/winshare.c diff --git a/0.72_My_PuTTY/windows/winstore.c b/0.73_My_PuTTY/windows/winstore.c similarity index 98% rename from 0.72_My_PuTTY/windows/winstore.c rename to 0.73_My_PuTTY/windows/winstore.c index 482e126..6722433 100644 --- a/0.72_My_PuTTY/windows/winstore.c +++ b/0.73_My_PuTTY/windows/winstore.c @@ -22,7 +22,7 @@ static const char *const reg_jumplist_key = PUTTY_REG_POS "\\Jumplist"; static const char *const reg_jumplist_value = "Recent sessions"; static const char *const puttystr = PUTTY_REG_POS "\\Sessions"; -#ifdef PERSOPORT +#ifdef MOD_PERSO #include "kitty_store.h" #endif @@ -33,7 +33,7 @@ DECL_WINDOWS_FUNCTION(static, HRESULT, SHGetFolderPathA, struct settings_w { HKEY sesskey; -#ifdef PERSOPORT +#ifdef MOD_PERSO HSettingsList list ; char *filename ; #endif @@ -50,7 +50,7 @@ settings_w *open_settings_w(const char *sessionname, char **errmsg) if (!sessionname || !*sessionname) sessionname = "Default Settings"; -#ifdef PERSOPORT +#ifdef MOD_PERSO //MessageBox(NULL,sessionname,sesspath,MB_OK); if( sessionname==NULL ) return NULL ; if( get_param("INIFILE")==SAVEMODE_DIR ) { @@ -99,7 +99,7 @@ settings_w *open_settings_w(const char *sessionname, char **errmsg) void write_setting_s(settings_w *handle, const char *key, const char *value) { -#ifdef PERSOPORT +#ifdef MOD_PERSO if (handle) if( get_param("INIFILE")==SAVEMODE_DIR ) { SettingsAddItem( handle->list, key, value ) ; @@ -113,7 +113,7 @@ void write_setting_s(settings_w *handle, const char *key, const char *value) void write_setting_i(settings_w *handle, const char *key, int value) { -#ifdef PERSOPORT +#ifdef MOD_PERSO if (handle) if( get_param("INIFILE")==SAVEMODE_DIR ) { char b[16] ; @@ -129,7 +129,7 @@ void write_setting_i(settings_w *handle, const char *key, int value) void close_settings_w(settings_w *handle) { -#ifdef PERSOPORT +#ifdef MOD_PERSO if (!handle) return ; if( GetReadOnlyFlag() ) return ; if( get_param("INIFILE")==SAVEMODE_DIR ) { @@ -161,7 +161,7 @@ void close_settings_w(settings_w *handle) struct settings_r { HKEY sesskey; -#ifdef PERSOPORT +#ifdef MOD_PERSO HSettingsList list ; #endif }; @@ -174,7 +174,7 @@ settings_r *open_settings_r(const char *sessionname) if (!sessionname || !*sessionname) sessionname = "Default Settings"; -#ifdef PERSOPORT +#ifdef MOD_PERSO //MessageBox(NULL,sessionname,sesspath,MB_OK); loadPath() ; if( get_param("INIFILE")==SAVEMODE_DIR ) { @@ -250,7 +250,7 @@ char *read_setting_s(settings_r *handle, const char *key) if (!handle) return NULL; -#ifdef PERSOPORT +#ifdef MOD_PERSO if( get_param("INIFILE")==SAVEMODE_DIR ) { return SettingsKey_str( handle->list, key ) ; } @@ -281,7 +281,7 @@ int read_setting_i(settings_r *handle, const char *key, int defvalue) { DWORD type, val, size; size = sizeof(val); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( get_param("INIFILE")==SAVEMODE_DIR ) { if( handle==NULL ) return defvalue ; return SettingsKey_int( handle->list, key, defvalue ) ; @@ -373,7 +373,7 @@ void write_setting_filename(settings_w *handle, void close_settings_r(settings_r *handle) { -#ifdef PERSOPORT +#ifdef MOD_PERSO if (!handle) return; if( get_param("INIFILE")==SAVEMODE_DIR ) { SettingsFree(handle->list); @@ -392,7 +392,7 @@ void del_settings(const char *sessionname) { HKEY subkey1; strbuf *sb; -#ifdef PERSOPORT +#ifdef MOD_PERSO if (!sessionname) return; if( get_param("INIFILE")==SAVEMODE_DIR ) { char *p, *p2; @@ -455,7 +455,7 @@ void del_settings(const char *sessionname) struct settings_e { HKEY key; int i; -#ifdef PERSOPORT +#ifdef MOD_PERSO int fromFile; HANDLE hFile; #endif @@ -466,7 +466,7 @@ settings_e *enum_settings_start(void) settings_e *ret; HKEY key; -#ifdef PERSOPORT +#ifdef MOD_PERSO if (*sesspath == '\0') { loadPath() ; } ret = snew(settings_e); @@ -494,7 +494,7 @@ settings_e *enum_settings_start(void) bool enum_settings_next(settings_e *e, strbuf *sb) { -#ifdef PERSOPORT +#ifdef MOD_PERSO WIN32_FIND_DATA FindFileData; HANDLE hFile; char buffer[MAX_PATH] ; @@ -567,12 +567,12 @@ if( (get_param("INIFILE")==SAVEMODE_DIR) && (!e->fromFile) ) { // On cherche le } } #endif - size_t regbuf_size = 256; + size_t regbuf_size = MAX_PATH + 1; char *regbuf = snewn(regbuf_size, char); bool success; while (1) { - DWORD retd = RegEnumKey(e->key, e->i++, regbuf, regbuf_size); + DWORD retd = RegEnumKey(e->key, e->i, regbuf, regbuf_size); if (retd != ERROR_MORE_DATA) { success = (retd == ERROR_SUCCESS); break; @@ -583,13 +583,14 @@ if( (get_param("INIFILE")==SAVEMODE_DIR) && (!e->fromFile) ) { // On cherche le if (success) unescape_registry_key(regbuf, sb); + e->i++; sfree(regbuf); return success; } void enum_settings_finish(settings_e *e) { -#ifdef PERSOPORT +#ifdef MOD_PERSO if( e==NULL ) return ; if(get_param("INIFILE")==SAVEMODE_DIR) { @@ -632,7 +633,7 @@ int verify_host_key(const char *hostname, int port, regname = strbuf_new(); hostkey_regname(regname, hostname, port, keytype); -#ifdef PERSOPORT +#ifdef MOD_PERSO int userMB; WIN32_FIND_DATA FindFile; if(*sshkpath == '\0') { loadPath() ; } @@ -931,7 +932,7 @@ void store_host_key(const char *hostname, int port, regname = strbuf_new(); hostkey_regname(regname, hostname, port, keytype); -#ifdef PERSOPORT +#ifdef MOD_PERSO if( get_param("INIFILE")==SAVEMODE_DIR ) { if(*sshkpath == '\0') { loadPath() ; } GetCurrentDirectory( (MAX_PATH*2), oldpath); @@ -1145,7 +1146,7 @@ void read_random_seed(noise_consumer_t consumer) void write_random_seed(void *data, int len) { -#ifdef PERSOPORT +#ifdef MOD_PERSO if( GetReadOnlyFlag() ) return ; #endif HANDLE seedf = access_random_seed(OPEN_W); @@ -1177,7 +1178,7 @@ static int transform_jumplist_registry char *old_value, *new_value; char *piterator_old, *piterator_new, *piterator_tmp; -#ifdef PERSOPORT +#ifdef MOD_PERSO old_value = NULL ; char RecentSessionsFile[2*MAX_PATH] ; if(*jumplistpath == '\0') { loadPath() ; } @@ -1252,7 +1253,7 @@ else { *old_value = '\0'; *(old_value + 1) = '\0'; } -#ifdef PERSOPORT +#ifdef MOD_PERSO } #endif @@ -1303,7 +1304,7 @@ else { ++piterator_new; /* Save the new list to the registry. */ -#ifdef PERSOPORT +#ifdef MOD_PERSO if( get_param("INIFILE")==SAVEMODE_DIR ) { FILE *fp ; if( !GetReadOnlyFlag() ) @@ -1330,7 +1331,7 @@ if( get_param("INIFILE")==SAVEMODE_DIR ) { sfree(old_value); /* Clean up and return. */ -#ifdef PERSOPORT +#ifdef MOD_PERSO if( get_param("INIFILE")!=SAVEMODE_DIR ) #endif RegCloseKey(pjumplist_key); diff --git a/0.72_My_PuTTY/windows/winstuff.h b/0.73_My_PuTTY/windows/winstuff.h similarity index 99% rename from 0.72_My_PuTTY/windows/winstuff.h rename to 0.73_My_PuTTY/windows/winstuff.h index 2748456..7f28992 100644 --- a/0.72_My_PuTTY/windows/winstuff.h +++ b/0.73_My_PuTTY/windows/winstuff.h @@ -167,7 +167,7 @@ struct FontSpec *fontspec_new( #endif #endif -#ifdef PERSOPORT +#ifdef MOD_PERSO #ifdef FDJ #define PUTTY_REG_POS_SAVE "Software\\9bis.com\\PuTTY_save" #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY" @@ -323,17 +323,17 @@ void write_aclip(int clipboard, char *, int, bool); #define FILTER_DYNLIB_FILES ("Dynamic Library Files (*.dll)\0*.dll\0" \ "All Files (*.*)\0*\0\0\0") -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) #define FILTER_IMAGE_FILES ("Image Files\0*.BMP;*.JPG;*.JPEG\0" \ "BMP Files (*.bmp)\0*.BMP\0" \ "JPEG Files (*.jpg)\0*.JPG;*.JPEG\0" \ "All Files (*.*)\0*\0\0\0") #endif -#ifdef PERSOPORT +#ifdef MOD_PERSO #define FILTER_ICON_FILES ("Icon Files (*.ico)\0*.ICO\0" \ "All Files (*.*)\0*\0\0\0") #endif -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM #define FILTER_EXE_FILES ("Executable Files (*.exe)\0*.EXE\0" \ "All Files (*.*)\0*\0\0\0") #endif diff --git a/0.72_My_PuTTY/windows/wintime.c b/0.73_My_PuTTY/windows/wintime.c similarity index 100% rename from 0.72_My_PuTTY/windows/wintime.c rename to 0.73_My_PuTTY/windows/wintime.c diff --git a/0.72_My_PuTTY/windows/winucs.c b/0.73_My_PuTTY/windows/winucs.c similarity index 100% rename from 0.72_My_PuTTY/windows/winucs.c rename to 0.73_My_PuTTY/windows/winucs.c diff --git a/0.72_My_PuTTY/windows/winutils.c b/0.73_My_PuTTY/windows/winutils.c similarity index 100% rename from 0.72_My_PuTTY/windows/winutils.c rename to 0.73_My_PuTTY/windows/winutils.c diff --git a/0.72_My_PuTTY/windows/winx11.c b/0.73_My_PuTTY/windows/winx11.c similarity index 100% rename from 0.72_My_PuTTY/windows/winx11.c rename to 0.73_My_PuTTY/windows/winx11.c diff --git a/0.72_My_PuTTY/x11fwd.c b/0.73_My_PuTTY/x11fwd.c similarity index 100% rename from 0.72_My_PuTTY/x11fwd.c rename to 0.73_My_PuTTY/x11fwd.c diff --git a/adb/adb.c b/adb/adb.c index a33000f..6bad3cc 100644 --- a/adb/adb.c +++ b/adb/adb.c @@ -1,7 +1,7 @@ /* * "Adb" backend. */ -#ifdef ADBPORT +#ifdef MOD_ADB #include #include diff --git a/cygterm/cygcfg.c b/cygterm/cygcfg.c index 43ee42f..16756d2 100644 --- a/cygterm/cygcfg.c +++ b/cygterm/cygcfg.c @@ -4,7 +4,7 @@ @ -0,0 +1,33 @@ */ -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM #include "putty.h" #include "dialog.h" diff --git a/cygterm/cygterm.c b/cygterm/cygterm.c index 6aac4c6..fdcba28 100644 --- a/cygterm/cygterm.c +++ b/cygterm/cygterm.c @@ -1,4 +1,4 @@ -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM #include /* sprintf */ #include diff --git a/kitty.c b/kitty.c index a31bb44..28072d7 100644 --- a/kitty.c +++ b/kitty.c @@ -97,7 +97,7 @@ int GetPasteCommandFlag(void) { return PasteCommandFlag ; } #ifdef FDJ int HyperlinkFlag = 1 ; #else -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK int HyperlinkFlag = 1 ; #else int HyperlinkFlag = 0 ; @@ -140,7 +140,7 @@ void SetProtectFlag( const int flag ) { ProtectFlag = flag ; } #endif // Definition de la section du fichier de configuration -#if (defined PERSOPORT) && (!defined FDJ) +#if (defined MOD_PERSO) && (!defined FDJ) #ifndef INIT_SECTION #define INIT_SECTION "KiTTY" #endif @@ -203,7 +203,7 @@ int GetIconeFlag(void) { return IconeFlag ; } void SetIconeFlag( const int flag ) { IconeFlag = flag ; } // Nombre d'icones differentes (identifiant commence a 1 dans le fichier .rc) -#ifndef PERSOPORT +#ifndef MOD_PERSO #define NB_ICONES 1 #define IDI_MAINICON_0 1 #define IDC_RESULT 1008 @@ -286,7 +286,7 @@ int PuttyFlag = 0 ; int GetPuttyFlag(void) { return PuttyFlag ; } void SetPuttyFlag( const int flag ) { PuttyFlag = flag ; } -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT // Flag pour inhiber le mécanisme de reconnexion automatique static int AutoreconnectFlag = 1 ; int GetAutoreconnectFlag( void ) { return AutoreconnectFlag ; } @@ -377,7 +377,7 @@ NOTIFYICONDATA TrayIcone ; #define TIMER_INIT 8701 #define TIMER_AUTOCOMMAND 8702 -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) #define TIMER_SLIDEBG 8703 #endif #define TIMER_REDRAW 8704 @@ -389,7 +389,7 @@ NOTIFYICONDATA TrayIcone ; /* #define TIMER_INIT 12341 #define TIMER_AUTOCOMMAND 12342 -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) #define TIMER_SLIDEBG 12343 #endif #define TIMER_REDRAW 12344 @@ -606,13 +606,13 @@ int get_param( const char * val ) { else if( !stricmp( val, "DIRECTORYBROWSE" ) ) return DirectoryBrowseFlag ; else if( !stricmp( val, "HYPERLINK" ) ) return HyperlinkFlag ; else if( !stricmp( val, "TRANSPARENCY" ) )return TransparencyFlag ; -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM else if( !stricmp( val, "ZMODEM" ) ) return ZModemFlag ; #endif -#ifdef IMAGEPORT +#ifdef MOD_BACKGROUNDIMAGE else if( !stricmp( val, "BACKGROUNDIMAGE" ) ) return GetBackgroundImageFlag() ; #endif -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM else if( !stricmp( val, "CYGTERM" ) ) return cygterm_get_flag() ; #endif // else if( !stricmp( val, "CONFIGBOXHEIGHT" ) ) return ConfigBoxHeight ; @@ -624,7 +624,7 @@ int get_param( const char * val ) { return 0 ; } -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) /* Le patch Background image ne marche plus bien sur la version PuTTY 0.61 - il est en erreur lorsqu'on passe par la config box - il est ok lorsqu'on demarrer par -load ou par duplicate session @@ -642,7 +642,7 @@ char * get_param_str( const char * val ) { return NULL ; } -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM void xyz_updateMenuItems(Terminal *term) { if( !ZModemFlag ) return ; HMENU m = GetSystemMenu(hwnd, FALSE); @@ -1241,7 +1241,7 @@ void CreateDefaultIniFile( void ) { writeINI( KittyIniFile, "ConfigBox", "#noexit", "no" ) ; writeINI( KittyIniFile, "ConfigBox", "#windowheight", "600" ) ; -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) writeINI( KittyIniFile, INIT_SECTION, "backgroundimage", "no" ) ; #endif writeINI( KittyIniFile, INIT_SECTION, "capslock", "no" ) ; @@ -1267,14 +1267,14 @@ void CreateDefaultIniFile( void ) { writeINI( KittyIniFile, INIT_SECTION, "shortcuts", "yes" ) ; writeINI( KittyIniFile, INIT_SECTION, "mouseshortcuts", "yes" ) ; #endif -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK #ifdef FDJ writeINI( KittyIniFile, INIT_SECTION, "hyperlink", "yes" ) ; #else writeINI( KittyIniFile, INIT_SECTION, "hyperlink", "no" ) ; #endif #endif -#ifndef NO_TRANSPARENCY +#ifndef MOD_NOTRANSPARENCY #ifdef FDJ writeINI( KittyIniFile, INIT_SECTION, "transparency", "yes" ) ; #else @@ -1299,17 +1299,17 @@ void CreateDefaultIniFile( void ) { writeINI( KittyIniFile, INIT_SECTION, "#ctrltab", "yes" ) ; writeINI( KittyIniFile, INIT_SECTION, "#KiClassName", "PuTTY" ) ; writeINI( KittyIniFile, INIT_SECTION, "maxblinkingtime", "5" ) ; -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT writeINI( KittyIniFile, INIT_SECTION, "#autoreconnect", "yes" ) ; writeINI( KittyIniFile, INIT_SECTION, "#ReconnectDelay", "5" ) ; #endif -#ifdef RUTTYPORT +#ifdef MOD_RUTTY writeINI( KittyIniFile, INIT_SECTION, "#scriptmode", "yes" ) ; #endif -#ifdef RUTTYPORT +#ifdef MOD_RUTTY writeINI( KittyIniFile, INIT_SECTION, "#adb", "yes" ) ; #endif -#ifdef PORTABLE +#ifdef MOD_PORTABLE writeINI( KittyIniFile, INIT_SECTION, "savemode", "dir" ) ; #else sprintf( buffer, "%s\\%s\\%s", getenv("APPDATA"), INIT_SECTION, DEFAULT_SAV_FILE ); @@ -1325,7 +1325,7 @@ void CreateDefaultIniFile( void ) { writeINI( KittyIniFile, INIT_SECTION, "slidedelay", "0" ) ; writeINI( KittyIniFile, INIT_SECTION, "winroll", "yes" ) ; writeINI( KittyIniFile, INIT_SECTION, "wintitle", "yes" ) ; -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM writeINI( KittyIniFile, INIT_SECTION, "zmodem", "yes" ) ; #endif writeINI( KittyIniFile, "Print", "height", "100" ) ; @@ -1389,7 +1389,7 @@ int DelParameter( const char * key, const char * name ) { // Test la configuration (mode file ou registry) et charge le fichier kitty.sav si besoin void GetSaveMode( void ) { -#ifndef PORTABLE +#ifndef MOD_PORTABLE char buffer[256] ; if( readINI( KittyIniFile, INIT_SECTION, "savemode", buffer ) ) { while( (buffer[strlen(buffer)-1]=='\n')||(buffer[strlen(buffer)-1]=='\r')||(buffer[strlen(buffer)-1]==' ')||(buffer[strlen(buffer)-1]=='\t') ) buffer[strlen(buffer)-1]='\0'; @@ -1899,7 +1899,7 @@ void SetNewIcon( HWND hwnd, char * iconefile, int icone, const int mode ) { // Modification de l'icone pour mettre l'icone de perte de connexion void SetConnBreakIcon( void ) { -#ifdef PERSOPORT +#ifdef MOD_PERSO HICON hIcon = NULL ; hIcon = LoadIcon( hInstIcons, MAKEINTRESOURCE(IDI_NOCON) ) ; SendMessage( hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon ); @@ -2645,21 +2645,21 @@ void ManageWinrol( HWND hwnd, int resize_action ) { InvalidateRect(hwnd, NULL, TRUE); } -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) BOOL load_bg_bmp() ; void clean_bg( void ) ; void RedrawBackground( HWND hwnd ) ; #endif void RefreshBackground( HWND hwnd ) { -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) if( GetBackgroundImageFlag() ) RedrawBackground( hwnd ) ; else #endif InvalidateRect( hwnd, NULL, true ) ; } -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) /* Changement du fond d'ecran */ int GetExt( const char * filename, char * ext) { int i; @@ -3458,7 +3458,7 @@ void SaveCurrentSetting( HWND hwnd ) { } // Procedures de generation du dump "memoire" (/savedump) -#ifdef SAVEDUMPPORT +#ifdef MOD_SAVEDUMP #include "kitty_savedump.c" #endif void InitShortcuts( void ) ; @@ -3480,7 +3480,7 @@ int InternalCommand( HWND hwnd, char * st ) { { RegCopyTree( HKEY_CURRENT_USER, "Software\\SimonTatham\\PuTTY", PUTTY_REG_POS ) ; return 1 ; } else if( !strcmp( st, "/backgroundimage" ) ) { SetBackgroundImageFlag( abs( GetBackgroundImageFlag() - 1 ) ) ; return 1 ; } else if( !strcmp( st, "/debug" ) ) { debug_flag = abs( debug_flag - 1 ) ; return 1 ; } -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK else if( !strcmp( st, "/hyperlink" ) ) { HyperlinkFlag = abs( HyperlinkFlag - 1 ) ; return 1 ; } else if( !strcmp( st, "/urlregex" ) ) { char b[1024] ; @@ -3492,7 +3492,7 @@ int InternalCommand( HWND hwnd, char * st ) { SaveCurrentSetting(hwnd); return 1 ; } -#ifdef SAVEDUMPPORT +#ifdef MOD_SAVEDUMP else if( !strcmp( st, "/savedump" ) ) { SaveDump() ; return 1 ; } #endif else if( !strcmp( st, "/screenshot" ) ) { @@ -3555,7 +3555,7 @@ int InternalCommand( HWND hwnd, char * st ) { } else if( !strcmp( st, "/size" ) ) { SizeFlag = abs( SizeFlag - 1 ) ; set_title( NULL, conf_get_str(conf,CONF_wintitle) ) ; return 1 ; } else if( !strcmp( st, "/transparency" ) ) { -#ifndef NO_TRANSPARENCY +#ifndef MOD_NOTRANSPARENCY if( (conf_get_int(conf,CONF_transparencynumber) == -1) || (TransparencyFlag == 0 ) ) { TransparencyFlag = 1 ; SetWindowLongPtr(MainHwnd, GWL_EXSTYLE, GetWindowLong(MainHwnd, GWL_EXSTYLE) | WS_EX_LAYERED ) ; @@ -3639,7 +3639,7 @@ int InternalCommand( HWND hwnd, char * st ) { else if( strstr( st, "/PrintCharSize " ) == st ) { PrintCharSize=atoi( st+15 ) ; return 1 ; } else if( strstr( st, "/PrintMaxLinePerPage " ) == st ) { PrintMaxLinePerPage=atoi( st+21) ; return 1 ; } else if( strstr( st, "/PrintMaxCharPerLine " ) == st ) { PrintMaxCharPerLine=atoi( st+21 ) ; return 1 ; } -#ifdef LAUNCHERPORT +#ifdef MOD_LAUNCHER else if( !strcmp( st, "/initlauncher" ) ) { InitLauncherRegistry() ; return 1 ; } #endif else if( !strcmp( st, "/winroll" ) ) { WinrolFlag = abs(WinrolFlag-1) ; return 1 ; } @@ -4475,7 +4475,7 @@ void ResetWindow(int reinit) ; void NegativeColours(HWND hwnd) { int i ; -#ifdef TUTTYPORT +#ifdef MOD_TUTTY for (i = 0; i < NCFGCOLOURS; i++) { #else for (i = 0; i < 22; i++) { @@ -4548,7 +4548,7 @@ void ChangeSettings(HWND hwnd) { //ChangeFontSize(hwnd,-1); } -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) // Gestion de l'image viewer int ManageViewer( HWND hwnd, WORD wParam ) { // Gestion du mode image if( wParam==VK_BACK ) @@ -4816,7 +4816,7 @@ int ManageShortcuts( HWND hwnd, const int* clips_system, int key_num, int shift_ } } -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) if( GetBackgroundImageFlag() && ImageViewerFlag ) { // Gestion du mode image if( ManageViewer( hwnd, key_num ) ) return 1 ; } @@ -4889,7 +4889,7 @@ int ManageShortcuts( HWND hwnd, const int* clips_system, int key_num, int shift_ } #endif -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) else if( GetBackgroundImageFlag() && (key == shortcuts_tab.imagechange) ) // Changement d'image de fond { if( NextBgImage( hwnd ) ) InvalidateRect(hwnd, NULL, TRUE) ; return 1 ; } #endif @@ -4908,7 +4908,7 @@ int ManageShortcuts( HWND hwnd, const int* clips_system, int key_num, int shift_ if (key_num == VK_ADD) { SendMessage( hwnd, WM_COMMAND, IDM_FONTUP, 0 ) ; return 1 ; } if (key_num == VK_SUBTRACT) { SendMessage( hwnd, WM_COMMAND, IDM_FONTDOWN, 0 ) ; return 1 ; } if (key_num == VK_NUMPAD0) { ChangeFontSize(hwnd,0) ; return 1 ; } -#ifdef LAUNCHERPORT +#ifdef MOD_LAUNCHER /* ====> Ne fonctionne pas !!! if (key_num == VK_LEFT ) //Fenetre KiTTY precedente { SendMessage( hwnd, WM_COMMAND, IDM_GOPREVIOUS, 0 ) ; return 1 ; } @@ -4942,7 +4942,7 @@ void SetPasteCommand( void ) { } // Initialisation des parametres a partir du fichier kitty.ini -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) void SetShrinkBitmapEnable(int) ; #endif @@ -4954,7 +4954,7 @@ void LoadParameters( void ) { if( ReadParameter( "Agent", "scrumble", buffer ) ) { if( !stricmp( buffer, "YES" ) ) SetScrumbleKeyFlag(1) ; } -#ifdef ADBPORT +#ifdef MOD_ADB if( ReadParameter( INIT_SECTION, "adb", buffer ) ) { if( !stricmp( buffer, "YES" ) ) SetADBFlag( 1 ) ; if( !stricmp( buffer, "NO" ) ) SetADBFlag( 0 ) ; @@ -4964,7 +4964,7 @@ void LoadParameters( void ) { if( ReadParameter( INIT_SECTION, "antiidledelay", buffer ) ) { AntiIdleCountMax = (int)floor(atoi(buffer)/10.0) ; if( AntiIdleCountMax<=0 ) AntiIdleCountMax =1 ; } if( ReadParameter( INIT_SECTION, "autostoresshkey", buffer ) ) { if( !stricmp( buffer, "YES" ) ) SetAutoStoreSSHKeyFlag( 1 ) ; } -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) if( debug_flag ) if( ReadParameter( INIT_SECTION, "backgroundimage", buffer ) ) { if( !stricmp( buffer, "NO" ) ) SetBackgroundImageFlag( 0 ) ; @@ -4986,14 +4986,14 @@ void LoadParameters( void ) { if( strlen( buffer ) > 0 ) { if( existdirectory(buffer) ) SetConfigDirectory( buffer ) ; } } if( ReadParameter( INIT_SECTION, "ctrltab", buffer ) ) { if( !stricmp( buffer, "NO" ) ) SetCtrlTabFlag( 0 ) ; } -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM if( ReadParameter( INIT_SECTION, "cygterm", buffer ) ) { if( !stricmp( buffer, "YES" ) ) cygterm_set_flag( 1 ) ; // Broken en 0.71 On desactive if( !stricmp( buffer, "NO" ) ) cygterm_set_flag( 0 ) ; } #endif -#ifdef HYPERLINKPORT -#ifndef NO_HYPERLINK +#ifdef MOD_HYPERLINK +#ifndef MOD_NOHYPERLINK if( ReadParameter( INIT_SECTION, "hyperlink", buffer ) ) { if( !stricmp( buffer, "NO" ) ) HyperlinkFlag = 0 ; if( !stricmp( buffer, "YES" ) ) HyperlinkFlag = 1 ; @@ -5069,33 +5069,33 @@ void LoadParameters( void ) { } } if( ReadParameter( INIT_SECTION, "wintitle", buffer ) ) { if( !stricmp( buffer, "NO" ) ) TitleBarFlag = 0 ; } -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM if( ReadParameter( INIT_SECTION, "zmodem", buffer ) ) { if( !stricmp( buffer, "NO" ) ) ZModemFlag = 0 ; if( !stricmp( buffer, "YES" ) ) ZModemFlag = 1 ; } #endif -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT if( ReadParameter( INIT_SECTION, "autoreconnect", buffer ) ) { if( !stricmp( buffer, "NO" ) ) AutoreconnectFlag = 0 ; } if( ReadParameter( INIT_SECTION, "ReconnectDelay", buffer ) ) { ReconnectDelay = atoi( buffer ) ; if( ReconnectDelay < 1 ) ReconnectDelay = 1 ; } #endif -#ifdef RUTTYPORT +#ifdef MOD_RUTTY if( ReadParameter( INIT_SECTION, "scriptmode", buffer ) ) { if( !stricmp( buffer, "YES" ) ) RuttyFlag = 1 ; if( !stricmp( buffer, "NO" ) ) RuttyFlag = 0 ; } #endif -#ifndef NO_TRANSPARENCY +#ifndef MOD_NOTRANSPARENCY if( ReadParameter( INIT_SECTION, "transparency", buffer ) ) { if( !stricmp( buffer, "YES" ) ) { TransparencyFlag = 1 ; } else { TransparencyFlag = 0 ; } } #endif -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) if( ReadParameter( INIT_SECTION, "shrinkbitmap", buffer ) ) { if( !stricmp( buffer, "YES" ) ) SetShrinkBitmapEnable(1) ; else SetShrinkBitmapEnable(0) ; } #endif @@ -5157,7 +5157,7 @@ void InitNameConfigFile( void ) { if( getenv("KITTY_INI_FILE") != NULL ) { strcpy( buffer, getenv("KITTY_INI_FILE") ) ; } if( !existfile( buffer ) ) { sprintf( buffer, "%s\\%s", InitialDirectory, DEFAULT_INIT_FILE ) ; -#ifdef PORTABLE +#ifdef MOD_PORTABLE if( !existfile( buffer ) ) { sprintf( buffer, "%s\\putty.ini", InitialDirectory ) ; if( !existfile( buffer ) ) { @@ -5182,7 +5182,7 @@ void InitNameConfigFile( void ) { if( KittySavFile != NULL ) { free( KittySavFile ) ; } KittySavFile=NULL ; sprintf( buffer, "%s\\%s", InitialDirectory, DEFAULT_SAV_FILE ) ; -#ifndef PORTABLE +#ifndef MOD_PORTABLE if( !existfile( buffer ) ) { sprintf( buffer, "%s\\%s\\%s", getenv("APPDATA"), INIT_SECTION, DEFAULT_SAV_FILE ) ; if( !existfile( buffer ) ) { @@ -5246,13 +5246,13 @@ void InitWinMain( void ) { // Initialisation de la version binaire sprintf( BuildVersionTime, "%s.%d @ %s", BUILD_VERSION, BUILD_SUBVERSION, BUILD_TIME ) ; -#ifdef PORTABLE +#ifdef MOD_PORTABLE sprintf( BuildVersionTime, "%s.%dp @ %s", BUILD_VERSION, BUILD_SUBVERSION, BUILD_TIME ) ; #endif -#ifdef NO_TRANSPARENCY +#ifdef MOD_NOTRANSPARENCY sprintf( BuildVersionTime, "%s.%dn @ %s", BUILD_VERSION, BUILD_SUBVERSION, BUILD_TIME ) ; #endif -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM // Par defaut Cygterm est desactive, il faut l'activer dans le fichier kitty.ini cygterm_set_flag(0); #endif @@ -5271,7 +5271,7 @@ void InitWinMain( void ) { // Initialisation du nom de la classe strcpy( KiTTYClassName, appname ) ; -#if (defined PERSOPORT) && (!defined FDJ) +#if (defined MOD_PERSO) && (!defined FDJ) if( ReadParameter( INIT_SECTION, "KiClassName", buffer ) ) { if( (strlen(buffer)>0) && (strlen(buffer)<128) ) { buffer[127]='\0'; strcpy( KiTTYClassName, buffer ) ; } } appname = KiTTYClassName ; @@ -5287,7 +5287,7 @@ void InitWinMain( void ) { LoadParameters() ; // Ajoute les répertoires InitialDirectory et ConfigDirectory au PATH -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM appendPath(InitialDirectory); // Initialise dans la fonction GetInitialDirectory if( strcmp(InitialDirectory,ConfigDirectory) ) { appendPath(ConfigDirectory); // Initialise dans LoadParameters @@ -5322,7 +5322,7 @@ void InitWinMain( void ) { LoadRegistryKey( hdlg ) ; InfoBoxClose( hdlg ) ; } -#ifdef PERSOPORT +#ifdef MOD_PERSO else { // la cle de registre existe deja if( WindowsCount( MainHwnd ) == 1 ) { // Si c'est le 1er kitty on sauvegarde la cle de registre avant de charger le fichier kitty.sav HWND hdlg = InfoBox( hinst, NULL ) ; @@ -5351,7 +5351,7 @@ void InitWinMain( void ) { if( (IniFileFlag == SAVEMODE_REG)||( IniFileFlag == SAVEMODE_FILE) ) RegTestOrCreate( HKEY_CURRENT_USER, buffer, NULL, NULL ) ; -#ifdef LAUNCHERPORT +#ifdef MOD_LAUNCHER // Initialisation du launcher sprintf( buffer, "%s\\%s", TEXT(PUTTY_REG_POS), "Launcher" ) ; if( (IniFileFlag == SAVEMODE_REG)||( IniFileFlag == SAVEMODE_FILE) ) diff --git a/kitty.h b/kitty.h index 3e48429..a13d08b 100644 --- a/kitty.h +++ b/kitty.h @@ -32,7 +32,7 @@ void SetCtrlTabFlag( const int flag ) ; int GetBackgroundImageFlag(void) ; void SetBackgroundImageFlag( const int flag ) ; -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT // Flag pour inhiber le mécanisme de reconnexion automatique int GetAutoreconnectFlag( void ) ; void SetAutoreconnectFlag( const int flag ) ; @@ -199,7 +199,7 @@ void SetSessionsInDefaultFlag( const int flag ) ; int GetDefaultSettingsFlag(void) ; void SetDefaultSettingsFlag( const int flag ) ; -#ifdef ADBPORT +#ifdef MOD_ADB // Flag pour inhiber le support d'ADB int GetADBFlag(void) ; void SetADBFlag( const int flag ) ; @@ -226,7 +226,7 @@ extern char * ConfigDirectory ; // Positionne un flag permettant de determiner si on est connecte extern int is_backend_connected ; -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT /* Variable permettant de savoir qu'on a deja ete connecte */ extern int is_backend_first_connected ; #endif @@ -384,10 +384,10 @@ void ChangeFontSize(HWND hwnd, int dec) ; void create_settings( const char * name ) ; -#ifdef LAUNCHERPORT +#ifdef MOD_LAUNCHER void InitLauncherRegistry( void ) ; #endif -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM void cygterm_set_flag( int flag ) ; int cygterm_get_flag( void ) ; #endif @@ -395,7 +395,7 @@ int cygterm_get_flag( void ) ; int getpid(void) ; // Definition de la section du fichier de configuration -#if (defined PERSOPORT) && (!defined FDJ) +#if (defined MOD_PERSO) && (!defined FDJ) #ifndef INIT_SECTION #define INIT_SECTION "KiTTY" @@ -447,7 +447,7 @@ int getpid(void) ; #endif #ifndef TIMER_SLIDEBG -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) #define TIMER_SLIDEBG 8703 #endif #endif @@ -483,7 +483,7 @@ int getpid(void) ; /************************************************* ** DEFINITION DES DEFINES *************************************************/ -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM #ifndef IDM_XYZSTART #define IDM_XYZSTART 0xA810 #endif @@ -584,7 +584,7 @@ void xyz_updateMenuItems(Terminal *term) ; #define IDM_CLEARLOGFILE 0xB100 #endif -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT #ifndef IDM_RESTARTSESSION #define IDM_RESTARTSESSION 0xB110 #endif diff --git a/kitty_commun.c b/kitty_commun.c index 4106209..6227912 100644 --- a/kitty_commun.c +++ b/kitty_commun.c @@ -8,7 +8,7 @@ // Flag permettant d'activer l'acces a du code particulier permettant d'avoir plus d'info dans le kitty.dmp int debug_flag = 0 ; -#ifdef PERSOPORT +#ifdef MOD_PERSO #ifndef SAVEMODE_REG #define SAVEMODE_REG 0 @@ -21,14 +21,14 @@ int debug_flag = 0 ; #endif // Flag pour le fonctionnement en mode "portable" (gestion par fichiers) -#ifdef PORTABLE +#ifdef MOD_PORTABLE int IniFileFlag = SAVEMODE_DIR ; #else int IniFileFlag = SAVEMODE_REG ; #endif // Flag permettant la gestion de l'arborscence (dossier=folder) dans le cas d'un savemode=dir -#ifdef PORTABLE +#ifdef MOD_PORTABLE int DirectoryBrowseFlag = 1 ; #else int DirectoryBrowseFlag = 0 ; @@ -60,7 +60,7 @@ static int ScrumbleKeyFlag = 0 ; int GetScrumbleKeyFlag(void) { return ScrumbleKeyFlag ; } void SetScrumbleKeyFlag( const int flag ) { ScrumbleKeyFlag = flag ; } -#ifdef ADBPORT +#ifdef MOD_ADB // Flag pour inhiber le support d'ADB static int ADBFlag = 1 ; int GetADBFlag(void) { return ADBFlag ; } @@ -68,7 +68,7 @@ void SetADBFlag( const int flag ) { ADBFlag = flag ; } #endif // Flag pour afficher l'image de fond -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) // Suite à PuTTY 0.61, le patch covidimus ne fonctionne plus tres bien // Il impose de demarrer les sessions avec -load meme depuis la config box (voir CONFIG.C) // Le patch est desactive par defaut @@ -267,7 +267,7 @@ int LoadParametersLight( void ) { // Positionne un flag permettant de determiner si on est connecte int is_backend_connected = 0 ; -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT int is_backend_first_connected = 0 ; void SetSSHConnected( int flag ) { is_backend_connected = flag ; diff --git a/kitty_commun.h b/kitty_commun.h index c14bb55..5e47bbc 100644 --- a/kitty_commun.h +++ b/kitty_commun.h @@ -40,7 +40,7 @@ void SetScrumbleKeyFlag( const int flag ) ; int GetBackgroundImageFlag(void) ; void SetBackgroundImageFlag( const int flag ) ; -#ifdef ADBPORT +#ifdef MOD_ADB // Flag pour inhiber le support d'ADB int GetADBFlag(void) ; void SetADBFlag( const int flag ) ; @@ -70,7 +70,7 @@ int LoadParametersLight( void ) ; // Positionne un flag permettant de determiner si on est connecte extern int is_backend_connected ; -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT extern int is_backend_first_connected ; #endif diff --git a/kitty_image.c b/kitty_image.c index 8609b51..9429243 100644 --- a/kitty_image.c +++ b/kitty_image.c @@ -6,7 +6,7 @@ // Essai de compilation séparée #ifdef FDJ -#undef IMAGEPORT +#undef MOD_BACKGROUNDIMAGE #endif #include @@ -15,8 +15,7 @@ #include "jpeg/jpeglib.h" #include -#ifdef IMAGEPORT -#ifdef NO +#ifdef MOD_BACKGROUNDIMAGE #include #include "putty.h" @@ -49,7 +48,6 @@ int return_font_height(void) ; int return_font_width(void) ; COLORREF return_colours258(void) ; -#endif static BOOL (WINAPI * pAlphaBlend)( HDC, int, int, int, int, HDC, int, int, int, int, BLENDFUNCTION ) = 0 ; @@ -376,7 +374,7 @@ static BOOL load_file_bmp(HBITMAP* rawImage, int* style, int* x, int* y) return TRUE; } -jmp_buf JPEG_bailout; +jmp_buf JPEG_bailout; int usePalette = 0; char *loadError = NULL; COLORREF skycolour = RGB(0, 0, 255); @@ -406,147 +404,147 @@ HBITMAP CreateHBitmap(int w, int h, LPVOID *lpBits) return bitmap; } -// LOADJPEGIMAGE -- Load JPEG image into memory -HBITMAP loadJPEGimage(FILE *input_file, HGLOBAL *LimageBitmap, int *LsizeX, int *LsizeY) -{ - int i; - LPBITMAPINFOHEADER bh; - DWORD bmpsize; - struct jpeg_decompress_struct cinfo; - struct jpeg_error_mgr jerr; - JSAMPARRAY colormap; - LPBYTE pix; - int linewid; - int pixbytes; - static LPBYTE sl = NULL; - static HGLOBAL imageBitmap = NULL; // In-memory bitmap - - sl = NULL; - imageBitmap = NULL; - if (setjmp(JPEG_bailout) != 0) { - /* Since we arrive here via longjmp() from - parts unknown, we may have allocated - the line buffer or bitmap prior to bailing - out. If they've been allocated, release them. */ - - if (sl != NULL) { - GlobalFree(sl); - sl = NULL; - } - if (imageBitmap != NULL) { - GlobalFree(imageBitmap); - imageBitmap = NULL; - } - return NULL; - } - cinfo.err = jpeg_std_error(&jerr); - jpeg_create_decompress(&cinfo); - jpeg_stdio_src(&cinfo, input_file); - jpeg_read_header(&cinfo, TRUE); - cinfo.desired_number_of_colors = 254; - cinfo.quantize_colors = usePalette; - jpeg_start_decompress(&cinfo); - - pixbytes = (usePalette ? 1 : 3); - sl = GlobalAlloc(GMEM_FIXED, cinfo.output_width * pixbytes); - if (sl == NULL) { - loadError = "Cannot allocate JPEG decoder row buffer"; - return NULL; - } - - linewid = ((((cinfo.output_width * pixbytes) + (sizeof(LONG) - 1)) / sizeof(LONG)) * sizeof(LONG)); - bmpsize = sizeof(BITMAPINFOHEADER) + - (usePalette ? (256 * sizeof(RGBQUAD)) : 0) + - (linewid * cinfo.output_height); - - imageBitmap = GlobalAlloc(GMEM_FIXED, bmpsize); - if (imageBitmap == NULL) { - loadError = "Cannot allocate bitmap for decoded JPEG image"; - GlobalFree(sl); - return NULL; - } - - // Plug in header fields with information from cinfo - - bh = (LPBITMAPINFOHEADER) imageBitmap; - pix = ((LPBYTE) imageBitmap) + sizeof(BITMAPINFOHEADER) + - (usePalette ? (256 * sizeof(RGBQUAD)) : 0); - bh->biSize = sizeof(BITMAPINFOHEADER); - bh->biWidth = cinfo.output_width; - bh->biHeight = cinfo.output_height; - bh->biPlanes = 1; - bh->biBitCount = usePalette ? 8 : 24; - bh->biCompression = BI_RGB; - bh->biSizeImage = 0; - bh->biXPelsPerMeter = bh->biYPelsPerMeter = 2835; - bh->biClrUsed = 0; - bh->biClrImportant = 0; - - /* Construct the palette from the colour map optimised - for the JPEG file. */ - - if (usePalette) { - colormap = cinfo.colormap; - for (i = 0; i < cinfo.actual_number_of_colors; i++) { - if (cinfo.num_components == 1) { - ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[i])->rgbRed = - ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[i])->rgbGreen = - ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[i])->rgbBlue = GETJSAMPLE(colormap[0][i]); - ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[i])->rgbReserved = 0; - } else { - ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[i])->rgbRed = GETJSAMPLE(colormap[0][i]); - ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[i])->rgbGreen = GETJSAMPLE(colormap[1][i]); - ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[i])->rgbBlue = GETJSAMPLE(colormap[2][i]); - ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[i])->rgbReserved = 0; - } - } - - /* Plug black and our text colour in the last two slots - of the palette so we canbe sure they're available. */ - - ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[254])->rgbRed = - ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[254])->rgbGreen = - ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[254])->rgbBlue = - ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[254])->rgbReserved = 0; - - ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[255])->rgbRed = GetRValue(skycolour); - ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[255])->rgbGreen = GetGValue(skycolour); - ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[255])->rgbBlue = GetBValue(skycolour); - ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[255])->rgbReserved = 0; - } - - // Return scan lines and transfer to the pixel array +// LOADJPEGIMAGE -- Load JPEG image into memory +HBITMAP loadJPEGimage(FILE *input_file, HGLOBAL *LimageBitmap, int *LsizeX, int *LsizeY) +{ + int i; + LPBITMAPINFOHEADER bh; + DWORD bmpsize; + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + JSAMPARRAY colormap; + LPBYTE pix; + int linewid; + int pixbytes; + static LPBYTE sl = NULL; + static HGLOBAL imageBitmap = NULL; // In-memory bitmap + + sl = NULL; + imageBitmap = NULL; + if (setjmp(JPEG_bailout) != 0) { + /* Since we arrive here via longjmp() from + parts unknown, we may have allocated + the line buffer or bitmap prior to bailing + out. If they've been allocated, release them. */ + + if (sl != NULL) { + GlobalFree(sl); + sl = NULL; + } + if (imageBitmap != NULL) { + GlobalFree(imageBitmap); + imageBitmap = NULL; + } + return NULL; + } + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_decompress(&cinfo); + jpeg_stdio_src(&cinfo, input_file); + jpeg_read_header(&cinfo, TRUE); + cinfo.desired_number_of_colors = 254; + cinfo.quantize_colors = usePalette; + jpeg_start_decompress(&cinfo); + + pixbytes = (usePalette ? 1 : 3); + sl = GlobalAlloc(GMEM_FIXED, cinfo.output_width * pixbytes); + if (sl == NULL) { + loadError = "Cannot allocate JPEG decoder row buffer"; + return NULL; + } + + linewid = ((((cinfo.output_width * pixbytes) + (sizeof(LONG) - 1)) / sizeof(LONG)) * sizeof(LONG)); + bmpsize = sizeof(BITMAPINFOHEADER) + + (usePalette ? (256 * sizeof(RGBQUAD)) : 0) + + (linewid * cinfo.output_height); + + imageBitmap = GlobalAlloc(GMEM_FIXED, bmpsize); + if (imageBitmap == NULL) { + loadError = "Cannot allocate bitmap for decoded JPEG image"; + GlobalFree(sl); + return NULL; + } + + // Plug in header fields with information from cinfo + + bh = (LPBITMAPINFOHEADER) imageBitmap; + pix = ((LPBYTE) imageBitmap) + sizeof(BITMAPINFOHEADER) + + (usePalette ? (256 * sizeof(RGBQUAD)) : 0); + bh->biSize = sizeof(BITMAPINFOHEADER); + bh->biWidth = cinfo.output_width; + bh->biHeight = cinfo.output_height; + bh->biPlanes = 1; + bh->biBitCount = usePalette ? 8 : 24; + bh->biCompression = BI_RGB; + bh->biSizeImage = 0; + bh->biXPelsPerMeter = bh->biYPelsPerMeter = 2835; + bh->biClrUsed = 0; + bh->biClrImportant = 0; + + /* Construct the palette from the colour map optimised + for the JPEG file. */ + + if (usePalette) { + colormap = cinfo.colormap; + for (i = 0; i < cinfo.actual_number_of_colors; i++) { + if (cinfo.num_components == 1) { + ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[i])->rgbRed = + ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[i])->rgbGreen = + ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[i])->rgbBlue = GETJSAMPLE(colormap[0][i]); + ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[i])->rgbReserved = 0; + } else { + ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[i])->rgbRed = GETJSAMPLE(colormap[0][i]); + ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[i])->rgbGreen = GETJSAMPLE(colormap[1][i]); + ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[i])->rgbBlue = GETJSAMPLE(colormap[2][i]); + ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[i])->rgbReserved = 0; + } + } + + /* Plug black and our text colour in the last two slots + of the palette so we canbe sure they're available. */ + + ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[254])->rgbRed = + ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[254])->rgbGreen = + ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[254])->rgbBlue = + ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[254])->rgbReserved = 0; + + ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[255])->rgbRed = GetRValue(skycolour); + ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[255])->rgbGreen = GetGValue(skycolour); + ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[255])->rgbBlue = GetBValue(skycolour); + ((LPRGBQUAD) &((LPBITMAPINFO) bh)->bmiColors[255])->rgbReserved = 0; + } + + // Return scan lines and transfer to the pixel array BYTE *pDst = NULL; HBITMAP hBitmap = CreateHBitmap(bh->biWidth, bh->biHeight, (void**)&pDst); int nStorageWidth = ((bh->biWidth * 24 + 31) & ~31) >> 3; //dword alignment JSAMPARRAY ppDst = &pDst; -/* - px = pix + (linewid * (bh->biHeight - 1)); - for (i = 0; i < (int) cinfo.output_height; i++) { - unsigned char *slp[1] = { sl }; - jpeg_read_scanlines(&cinfo, slp, 1); - if (usePalette) { - memcpy(px, sl, cinfo.output_width); - } else { - int j, k; - - if (cinfo.num_components == 3) { - for (j = k = 0; j < (int) cinfo.output_width; j++, k += 3) { - px[k] = sl[k + 2]; - px[k + 1] = sl[k + 1]; - px[k + 2] = sl[k]; - } - } else { - for (j = k = 0; j < (int) cinfo.output_width; j++, k += 3) { - px[k] = sl[j]; - px[k + 1] = sl[j]; - px[k + 2] = sl[j]; - } - } - } - px -= linewid; - } +/* + px = pix + (linewid * (bh->biHeight - 1)); + for (i = 0; i < (int) cinfo.output_height; i++) { + unsigned char *slp[1] = { sl }; + jpeg_read_scanlines(&cinfo, slp, 1); + if (usePalette) { + memcpy(px, sl, cinfo.output_width); + } else { + int j, k; + + if (cinfo.num_components == 3) { + for (j = k = 0; j < (int) cinfo.output_width; j++, k += 3) { + px[k] = sl[k + 2]; + px[k + 1] = sl[k + 1]; + px[k + 2] = sl[k]; + } + } else { + for (j = k = 0; j < (int) cinfo.output_width; j++, k += 3) { + px[k] = sl[j]; + px[k + 1] = sl[j]; + px[k + 2] = sl[j]; + } + } + } + px -= linewid; + } */ pDst = pDst + (cinfo.output_height-1)*nStorageWidth ; while (cinfo.output_scanline < cinfo.output_height) { @@ -567,16 +565,16 @@ while (cinfo.output_scanline < cinfo.output_height) { //pDst += nStorageWidth; pDst -= nStorageWidth; } - - GlobalFree(sl); - jpeg_finish_decompress(&cinfo); - jpeg_destroy_decompress(&cinfo); - - *LsizeX = (int) bh->biWidth; - *LsizeY = (int) bh->biHeight; - *LimageBitmap = imageBitmap; - return hBitmap; -} + + GlobalFree(sl); + jpeg_finish_decompress(&cinfo); + jpeg_destroy_decompress(&cinfo); + + *LsizeX = (int) bh->biWidth; + *LsizeY = (int) bh->biHeight; + *LimageBitmap = imageBitmap; + return hBitmap; +} static BOOL load_file_jpeg(HBITMAP* rawImage, int* style, int* x, int* y) { @@ -590,7 +588,7 @@ static BOOL load_file_jpeg(HBITMAP* rawImage, int* style, int* x, int* y) { if( ( fp=fopen( conf_get_filename( conf,CONF_bg_image_filename)->path, "rb" ) ) == NULL ) return FALSE ; - if( *rawImage!=NULL ) { DeleteObject( *rawImage ) ; *rawImage=NULL ; } + if( *rawImage!=NULL ) { DeleteObject( *rawImage ) ; *rawImage=NULL ; } *rawImage = loadJPEGimage(fp, &LimageBitmap,&LsizeX, &LsizeY) ; if( rawImage == NULL ) res =FALSE ; fclose( fp ) ; @@ -1332,7 +1330,7 @@ void RedrawBackground( HWND hwnd ) { } -#ifdef STARTBUTTON +#ifdef MOD_STARTBUTTON /* * Patch permettant de gerer le probleme de chargement de l'image de fond arrive avec putty 0.61 */ diff --git a/kitty_image.h b/kitty_image.h index 92605cf..54263dd 100644 --- a/kitty_image.h +++ b/kitty_image.h @@ -1,4 +1,4 @@ -#ifdef IMAGEPORT +#ifdef MOD_BACKGROUNDIMAGE #include diff --git a/kitty_launcher.c b/kitty_launcher.c index 72971af..7107934 100644 --- a/kitty_launcher.c +++ b/kitty_launcher.c @@ -1,4 +1,4 @@ -#ifdef LAUNCHERPORT +#ifdef MOD_LAUNCHER // define recupere de WIN_RES.H #ifndef IDI_PUTTY_LAUNCH @@ -725,7 +725,7 @@ int WINAPI Launcher_WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int s // } } return msg.wParam; - } + } #endif void RunConfig( Conf * conf ) { diff --git a/kitty_savedump.c b/kitty_savedump.c index 9d6d608..e404aab 100644 --- a/kitty_savedump.c +++ b/kitty_savedump.c @@ -325,6 +325,7 @@ void SaveDumpConfig( FILE *fp, Conf * conf ) { /* Keyboard options */ fprintf( fp, "bksp_is_delete=%d\n", conf_get_bool(conf,CONF_bksp_is_delete) ) ; + fprintf( fp, "enter_sends_crlf=%d\n", conf_get_int(conf,CONF_enter_sends_crlf) ) ; fprintf( fp, "rxvt_homeend=%d\n", conf_get_int(conf,CONF_rxvt_homeend) ) ; fprintf( fp, "funky_type=%d\n", conf_get_int(conf,CONF_funky_type) ) ; fprintf( fp, "no_applic_c=%d\n", conf_get_bool(conf,CONF_no_applic_c) ) ; @@ -478,8 +479,8 @@ void SaveDumpConfig( FILE *fp, Conf * conf ) { fprintf( fp, "crhaslf=%d\n", conf_get_bool(conf,CONF_crhaslf) ) ; fprintf( fp, "winclass=%s\n", conf_get_str(conf,CONF_winclass) ) ; -#ifdef PERSOPORT - /* PERSOPORT Options */ +#ifdef MOD_PERSO + /* MOD_PERSO Options */ //fprintf( fp, "bcdelay=%d\n", conf_get_int(conf,CONF_bcdelay) ) ; // Non present systematiquement //fprintf( fp, "initdelay=%d\n", conf_get_int(conf,CONF_initdelay) ) ; // Non present systematiquement fprintf( fp, "transparencynumber=%d\n", conf_get_int(conf,CONF_transparencynumber) ) ; @@ -524,13 +525,10 @@ void SaveDumpConfig( FILE *fp, Conf * conf ) { fprintf( fp, "comment=%s\n", conf_get_str(conf,CONF_comment) ) ; fprintf( fp, "scp_auto_pwd=%d\n", conf_get_int(conf, CONF_scp_auto_pwd)); #endif -#ifdef ACSPORT - fprintf( fp, "acs_in_utf=%d\n", conf_get_bool(conf, CONF_acs_in_utf)); -#endif -#ifdef PRINTCLIPPORT +#ifdef MOD_PRINTCLIP fprintf( fp, "printclip=%d\n", conf_get_int(conf,CONF_printclip) ) ; #endif -#ifdef RUTTYPORT +#ifdef MOD_RUTTY /* rutty: scripting options */ fprintf( fp, "ScriptFileName=%s\n", conf_get_filename(conf,CONF_script_filename)->path ) ; fprintf( fp, "ScriptMode=%d\n", conf_get_int(conf,CONF_script_mode) ) ; @@ -545,14 +543,14 @@ void SaveDumpConfig( FILE *fp, Conf * conf ) { fprintf( fp, "ScriptWait=%s\n", conf_get_str(conf,CONF_script_waitfor) ) ; fprintf( fp, "ScriptHalt=%s\n", conf_get_str(conf,CONF_script_halton) ) ; #endif -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM /* Cygterm options */ fprintf( fp, "cygautopath=%d\n", conf_get_int(conf,CONF_cygautopath) ) ; fprintf( fp, "cygterm64=%d\n", conf_get_int(conf,CONF_cygterm64) ) ; fprintf( fp, "cygcmd=%s\n", conf_get_str(conf,CONF_cygcmd) ) ; fprintf( fp, "alt_metabit=%d\n", conf_get_int(conf,CONF_alt_metabit) ) ; #endif -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) /* Image Options */ fprintf( fp, "bg_opacity=%d\n", conf_get_int(conf,CONF_bg_opacity) ) ; fprintf( fp, "bg_slideshow=%d\n", conf_get_int(conf,CONF_bg_slideshow) ) ; @@ -563,12 +561,12 @@ void SaveDumpConfig( FILE *fp, Conf * conf ) { fprintf( fp, "bg_image_abs_y=%d\n", conf_get_int(conf,CONF_bg_image_abs_y) ) ; fprintf( fp, "bg_image_abs_fixed=%d\n", conf_get_int(conf,CONF_bg_image_abs_fixed) ) ; #endif -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT /* Reconnect Options */ fprintf( fp, "wakeup_reconnect=%d\n", conf_get_int(conf,CONF_wakeup_reconnect) ) ; fprintf( fp, "failure_reconnect=%d\n", conf_get_int(conf,CONF_failure_reconnect) ) ; #endif -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK /* Hyperlink Options */ fprintf( fp, "url_ctrl_click=%d\n", conf_get_int(conf,CONF_url_ctrl_click) ) ; fprintf( fp, "url_underline=%d\n", conf_get_int(conf,CONF_url_underline) ) ; @@ -579,7 +577,7 @@ void SaveDumpConfig( FILE *fp, Conf * conf ) { fprintf( fp, "urlhack_default_regex=%s\n", urlhack_default_regex ) ; fprintf( fp, "urlhack_liberal_regex=%s\n", urlhack_liberal_regex ) ; #endif -#ifdef TUTTYPORT +#ifdef MOD_TUTTY /* TuTTY port Options */ fprintf( fp, "window_closable=%d\n", conf_get_int(conf,CONF_window_closable) ) ; fprintf( fp, "window_minimizable=%d\n", conf_get_int(conf,CONF_window_minimizable) ) ; @@ -590,7 +588,7 @@ void SaveDumpConfig( FILE *fp, Conf * conf ) { fprintf( fp, "under_colour=%d\n", conf_get_int(conf,CONF_under_colour) ) ; fprintf( fp, "sel_colour=%d\n", conf_get_int(conf,CONF_sel_colour) ) ; #endif -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM /* ZModem Options */ fprintf( fp, "rzcommand=%s\n", conf_get_filename(conf,CONF_rzcommand)->path ) ; fprintf( fp, "rzoptions=%s\n", conf_get_str(conf,CONF_rzoptions) ) ; @@ -598,11 +596,11 @@ void SaveDumpConfig( FILE *fp, Conf * conf ) { fprintf( fp, "szoptions=%s\n", conf_get_str(conf,CONF_szoptions) ) ; fprintf( fp, "zdownloaddir=%s\n", conf_get_str(conf,CONF_zdownloaddir) ) ; #endif -#ifdef PORTKNOCKINGPORT +#ifdef MOD_PORTKNOCKING /* Port knocking Options */ fprintf( fp, "portknocking=%s\n", conf_get_str(conf,CONF_portknockingoptions) ) ; #endif -#ifdef DISABLEALTGRPORT +#ifdef MOD_DISABLEALTGR /* Disable AltGr Options */ fprintf( fp, "disablealtgr=%d\n", conf_get_int(conf,CONF_disablealtgr) ) ; #endif @@ -635,13 +633,13 @@ void SaveDumpConfig( FILE *fp, Conf * conf ) { fprintf( fp, "WinHeight=%d\nWinrolFlag=%d\nAutoSendToTray=%d\nNoKittyFileFlag=%d\nConfigBoxHeight=%d\nConfigBoxWindowHeight=%d\nConfigBoxNoExitFlag=%d\nUserPassSSHNoSave=%d\nPuttyFlag=%d\n",WinHeight,WinrolFlag,AutoSendToTray,NoKittyFileFlag,ConfigBoxHeight,ConfigBoxWindowHeight,ConfigBoxNoExitFlag,GetUserPassSSHNoSave(),PuttyFlag); fprintf( fp,"BackgroundImageFlag=%d\n",GetBackgroundImageFlag() ); -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT fprintf( fp,"AutoreconnectFlag=%d\nReconnectDelay=%d\n",AutoreconnectFlag,ReconnectDelay ); #endif -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM fprintf( fp,"CygTermFlag=%d\n",cygterm_get_flag() ); #endif -#ifdef ADBPORT +#ifdef MOD_ADB fprintf( fp,"ADBFlag=%d\n",GetADBFlag() ); #endif if( PasswordConf!= NULL ) fprintf( fp, "PasswordConf=%s\n", PasswordConf ) ; @@ -854,7 +852,7 @@ void SaveDumpFile( char * filename ) { fputs( "\n@ Private key file @\n\n", fpout ) ; SaveDebugFile( conf_get_filename(conf,CONF_keyfile)->path, fpout ) ; } -#ifdef RUTTYPORT +#ifdef MOD_RUTTY if( existfile( conf_get_filename(conf,CONF_script_filename)->path ) ) { fputs( "\n@ RuTTY script file @\n\n", fpout ) ; SaveDebugFile( conf_get_filename(conf,CONF_script_filename)->path, fpout ) ; diff --git a/kitty_settings.c b/kitty_settings.c index 50b6d7c..8d5488d 100644 --- a/kitty_settings.c +++ b/kitty_settings.c @@ -149,6 +149,7 @@ void save_open_settings_forced(char *filename, Conf *conf) { write_setting_b_forced(sesskey, "RFCEnviron", conf_get_bool(conf, CONF_rfc_environ)); write_setting_b_forced(sesskey, "PassiveTelnet", conf_get_bool(conf, CONF_passive_telnet)); write_setting_b_forced(sesskey, "BackspaceIsDelete", conf_get_bool(conf, CONF_bksp_is_delete)); + write_setting_i_forced(sesskey, "EnterSendsCrLf", conf_get_int(conf, CONF_enter_sends_crlf)); write_setting_i_forced(sesskey, "RXVTHomeEnd", conf_get_int(conf, CONF_rxvt_homeend)); write_setting_i_forced(sesskey, "LinuxFunctionKeys", conf_get_int(conf, CONF_funky_type)); write_setting_b_forced(sesskey, "NoApplicationKeys", conf_get_bool(conf, CONF_no_applic_k)); @@ -221,7 +222,7 @@ void save_open_settings_forced(char *filename, Conf *conf) { write_setting_b_forced(sesskey, "TrueColour", conf_get_bool(conf, CONF_true_colour)); write_setting_i_forced(sesskey, "BoldAsColour", conf_get_int(conf, CONF_bold_style)-1); -#ifdef TUTTYPORT +#ifdef MOD_TUTTY write_setting_i_forced(sesskey, "WindowClosable", conf_get_int(conf, CONF_window_closable) ); write_setting_i_forced(sesskey, "WindowMinimizable", conf_get_int(conf, CONF_window_minimizable) ); write_setting_i_forced(sesskey, "WindowMaximizable", conf_get_int(conf, CONF_window_maximizable) ); @@ -324,7 +325,7 @@ void save_open_settings_forced(char *filename, Conf *conf) { write_setting_b_forced(sesskey, "ConnectionSharingDownstream", conf_get_bool(conf, CONF_ssh_connection_sharing_downstream)); wmap_forced(sesskey, "SSHManualHostKeys", conf, CONF_ssh_manual_hostkeys, false); /* rutty: */ -#ifdef RUTTYPORT +#ifdef MOD_RUTTY write_setting_filename_forced(sesskey, "ScriptFileName", conf_get_filename(conf, CONF_script_filename)); write_setting_i_forced(sesskey, "ScriptMode", (conf_get_int(conf, CONF_script_mode)!=SCRIPT_PLAY)?SCRIPT_STOP:conf_get_int(conf, CONF_script_mode)); /* dont save with record on */ write_setting_i_forced(sesskey, "ScriptLineDelay", conf_get_int(conf, CONF_script_line_delay)); @@ -338,11 +339,11 @@ void save_open_settings_forced(char *filename, Conf *conf) { write_setting_s_forced(sesskey, "ScriptWait", conf_get_str(conf, CONF_script_waitfor)); write_setting_s_forced(sesskey, "ScriptHalt", conf_get_str(conf, CONF_script_halton)); #endif /* rutty */ -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT write_setting_i_forced(sesskey, "WakeupReconnect", conf_get_int(conf,CONF_wakeup_reconnect) ); write_setting_i_forced(sesskey, "FailureReconnect", conf_get_int(conf,CONF_failure_reconnect) ); #endif -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) if( GetBackgroundImageFlag() ) { write_setting_i_forced(sesskey, "BgOpacity", conf_get_int(conf, CONF_bg_opacity) ); write_setting_i_forced(sesskey, "BgSlideshow", conf_get_int(conf, CONF_bg_slideshow) ); @@ -354,7 +355,7 @@ void save_open_settings_forced(char *filename, Conf *conf) { write_setting_i_forced(sesskey, "BgImagePlacement", conf_get_int(conf, CONF_bg_image_abs_fixed) ); } #endif -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK /* * HACK: PuttyTray / Nutty * Hyperlink stuff: Save hyperlink settings @@ -364,7 +365,7 @@ void save_open_settings_forced(char *filename, Conf *conf) { write_setting_i_forced(sesskey, "HyperlinkBrowserUseDefault", conf_get_int(conf, CONF_url_defbrowser)); write_setting_filename_forced(sesskey, "HyperlinkBrowser", conf_get_filename(conf, CONF_url_browser)); write_setting_i_forced(sesskey, "HyperlinkRegularExpressionUseDefault", conf_get_int(conf, CONF_url_defregex)); -#ifndef NO_HYPERLINK +#ifndef MOD_NOHYPERLINK if( !strcmp(conf_get_str(conf, CONF_url_regex),"@°@°@NO REGEX--") ) write_setting_s_forced(sesskey, "HyperlinkRegularExpression", urlhack_default_regex ) ; else @@ -373,21 +374,21 @@ void save_open_settings_forced(char *filename, Conf *conf) { write_setting_s_forced(sesskey, "HyperlinkRegularExpression", conf_get_str(conf, CONF_url_regex)); #endif #endif -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM //if (do_host) write_setting_i_forced(sesskey, "CygtermAltMetabit", conf_get_int(conf, CONF_alt_metabit)); write_setting_i_forced(sesskey, "CygtermAutoPath", conf_get_int(conf, CONF_cygautopath) ); write_setting_i_forced(sesskey, "Cygterm64", conf_get_int(conf, CONF_cygterm64)); write_setting_s_forced(sesskey, "CygtermCommand", conf_get_str(conf, CONF_cygcmd) ); #endif -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM write_setting_filename_forced(sesskey, "rzCommand", conf_get_filename(conf, CONF_rzcommand) ); write_setting_s_forced(sesskey, "rzOptions", conf_get_str(conf, CONF_rzoptions) ); write_setting_filename_forced(sesskey, "szCommand", conf_get_filename(conf, CONF_szcommand) ); write_setting_s_forced(sesskey, "szOptions", conf_get_str(conf, CONF_szoptions) ); write_setting_s_forced(sesskey, "zDownloadDir", conf_get_str(conf, CONF_zdownloaddir) ); #endif -#ifdef PERSOPORT +#ifdef MOD_PERSO if( conf_get_int(conf, CONF_transparencynumber)<-1 ) conf_set_int(conf, CONF_transparencynumber,-1) ; if( conf_get_int(conf, CONF_transparencynumber)>255 ) conf_set_int(conf, CONF_transparencynumber,255) ; write_setting_i_forced(sesskey, "TransparencyValue", conf_get_int(conf, CONF_transparencynumber) ) ; @@ -421,7 +422,7 @@ void save_open_settings_forced(char *filename, Conf *conf) { strcpy( PassKey, "" ) ; } char pst[4096] ; -#ifndef NO_PASSWORD +#ifndef MOD_NOPASSWORD strcpy( pst, conf_get_str(conf, CONF_password ) ); MASKPASS(pst); cryptstring( pst, PassKey ) ; @@ -432,13 +433,10 @@ void save_open_settings_forced(char *filename, Conf *conf) { write_setting_s_forced(sesskey, "Comment", conf_get_str(conf, CONF_comment) ); write_setting_i_forced(sesskey, "SCPAutoPwd", conf_get_int(conf, CONF_scp_auto_pwd)); #endif -#ifdef ACSPORT - write_setting_b_forced(sesskey, "ACSinUTF", conf_get_bool(conf, CONF_acs_in_utf)); -#endif -#ifdef PORTKNOCKINGPORT +#ifdef MOD_PORTKNOCKING write_setting_s_forced(sesskey, "PortKnocking", conf_get_str(conf, CONF_portknockingoptions) ); #endif -#ifdef DISABLEALTGRPORT +#ifdef MOD_DISABLEALTGR write_setting_i_forced(sesskey, "DisableAltGr", conf_get_int(conf, CONF_disablealtgr)); #endif // END COPY/PASTE @@ -461,7 +459,7 @@ void load_open_settings_forced(char *filename, Conf *conf) { // BEGIN COPY/PASTE int i; char *prot; -#ifdef PERSOPORT +#ifdef MOD_PERSO /* * HACK: PuTTY-url * Set font quality to cleartype on Windows Vista and above @@ -693,6 +691,7 @@ void load_open_settings_forced(char *filename, Conf *conf) { gppb_forced(sesskey, "RFCEnviron", false, conf, CONF_rfc_environ); gppb_forced(sesskey, "PassiveTelnet", false, conf, CONF_passive_telnet); gppb_forced(sesskey, "BackspaceIsDelete", true, conf, CONF_bksp_is_delete); + gppi_forced(sesskey, "EnterSendsCrLf", 0, conf, CONF_enter_sends_crlf); gppi_forced(sesskey, "RXVTHomeEnd", 0, conf, CONF_rxvt_homeend); gppi_forced(sesskey, "LinuxFunctionKeys", 0, conf, CONF_funky_type); gppb_forced(sesskey, "NoApplicationKeys", false, conf, CONF_no_applic_k); @@ -731,7 +730,7 @@ void load_open_settings_forced(char *filename, Conf *conf) { gppb_forced(sesskey, "TelnetRet", true, conf, CONF_telnet_newline); gppi_forced(sesskey, "LocalEcho", AUTO, conf, CONF_localecho); gppi_forced(sesskey, "LocalEdit", AUTO, conf, CONF_localedit); -#if (defined PERSOPORT) && (!defined FDJ) +#if (defined MOD_PERSO) && (!defined FDJ) gpps_forced(sesskey, "Answerback", "KiTTY", conf, CONF_answerback); #else gpps_forced(sesskey, "Answerback", "PuTTY", conf, CONF_answerback); @@ -770,7 +769,7 @@ void load_open_settings_forced(char *filename, Conf *conf) { / 1000 #endif ); -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK gppi_forced(sesskey, "ScrollbackLines", 10000, conf, CONF_savelines); #else gppi_forced(sesskey, "ScrollbackLines", 2000, conf, CONF_savelines); @@ -786,7 +785,7 @@ void load_open_settings_forced(char *filename, Conf *conf) { gppi_forced(sesskey, "TermWidth", 80, conf, CONF_width); gppi_forced(sesskey, "TermHeight", 24, conf, CONF_height); gppfont_forced(sesskey, "Font", conf, CONF_font); -#ifdef PERSOPORT +#ifdef MOD_PERSO /* * HACK: PuTTY-url * Set font quality to cleartype on Windows Vista and higher @@ -807,7 +806,7 @@ void load_open_settings_forced(char *filename, Conf *conf) { gppb_forced(sesskey, "TrueColour", true, conf, CONF_true_colour); i = gppi_raw_forced(sesskey, "BoldAsColour", 1); conf_set_int(conf, CONF_bold_style, i+1); -#ifdef TUTTYPORT +#ifdef MOD_TUTTY gppi_forced(sesskey, "WindowClosable", 1, conf, CONF_window_closable); gppi_forced(sesskey, "WindowMinimizable", 1, conf, CONF_window_minimizable); gppi_forced(sesskey, "WindowMaximizable", 1, conf, CONF_window_maximizable); @@ -896,7 +895,7 @@ void load_open_settings_forced(char *filename, Conf *conf) { gppb_forced(sesskey, "CJKAmbigWide", false, conf, CONF_cjk_ambig_wide); gppb_forced(sesskey, "UTF8Override", true, conf, CONF_utf8_override); gpps_forced(sesskey, "Printer", "", conf, CONF_printer); -#ifdef PRINTCLIPPORT +#ifdef MOD_PRINTCLIP if( !strcmp( conf_get_str(conf,CONF_printer),PRINT_TO_CLIPBOARD_STRING) ) { conf_set_int(conf,CONF_printclip,1) ; } else { conf_set_int(conf,CONF_printclip,0) ; } #endif @@ -963,7 +962,7 @@ void load_open_settings_forced(char *filename, Conf *conf) { conf, CONF_ssh_connection_sharing_downstream); gppmap_forced(sesskey, "SSHManualHostKeys", conf, CONF_ssh_manual_hostkeys); /* rutty: */ -#ifdef RUTTYPORT +#ifdef MOD_RUTTY gppfile_forced(sesskey, "ScriptFileName", conf, CONF_script_filename); gppi_forced(sesskey, "ScriptMode", 0, conf, CONF_script_mode); gppi_forced(sesskey, "ScriptLineDelay", 0, conf, CONF_script_line_delay); @@ -977,11 +976,11 @@ void load_open_settings_forced(char *filename, Conf *conf) { gpps_forced(sesskey, "ScriptWait", "", conf, CONF_script_waitfor); gpps_forced(sesskey, "ScriptHalt", "", conf, CONF_script_halton); #endif /* rutty */ -#ifdef RECONNECTPORT +#ifdef MOD_RECONNECT gppi_forced(sesskey, "WakeupReconnect", 0, conf, CONF_wakeup_reconnect ); gppi_forced(sesskey, "FailureReconnect", 0, conf, CONF_failure_reconnect ); #endif -#if (defined IMAGEPORT) && (!defined FDJ) +#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) gppi_forced(sesskey, "BgOpacity", 50, conf, CONF_bg_opacity ); gppi_forced(sesskey, "BgSlideshow", 0, conf, CONF_bg_slideshow ); gppi_forced(sesskey, "BgType", 0, conf, CONF_bg_type ); @@ -991,7 +990,7 @@ void load_open_settings_forced(char *filename, Conf *conf) { gppi_forced(sesskey, "BgImageAbsoluteY", 0, conf, CONF_bg_image_abs_y ); gppi_forced(sesskey, "BgImagePlacement", 0, conf, CONF_bg_image_abs_fixed ); #endif -#ifdef HYPERLINKPORT +#ifdef MOD_HYPERLINK /* * HACK: PuttyTray / Nutty * Hyperlink stuff: Load hyperlink settings @@ -1002,24 +1001,24 @@ void load_open_settings_forced(char *filename, Conf *conf) { gppfile_forced(sesskey, "HyperlinkBrowser", conf, CONF_url_browser); gppi_forced(sesskey, "HyperlinkRegularExpressionUseDefault", 1, conf, CONF_url_defregex); -#ifndef NO_HYPERLINK +#ifndef MOD_NOHYPERLINK gpps_forced(sesskey, "HyperlinkRegularExpression", urlhack_default_regex, conf, CONF_url_regex); #endif #endif -#ifdef CYGTERMPORT +#ifdef MOD_CYGTERM gppi_forced(sesskey, "CygtermAltMetabit", 0, conf, CONF_alt_metabit); gppi_forced(sesskey, "CygtermAutoPath", 1, conf, CONF_cygautopath ); gppi_forced(sesskey, "Cygterm64", 0, conf, CONF_cygterm64); gpps_forced(sesskey, "CygtermCommand", "", conf, CONF_cygcmd ); #endif -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM gppfile_forced(sesskey, "rzCommand", conf, CONF_rzcommand ); gpps_forced(sesskey, "rzOptions", "-e -v", conf, CONF_rzoptions ); gppfile_forced(sesskey, "szCommand", conf, CONF_szcommand ); gpps_forced(sesskey, "szOptions", "-e -v", conf, CONF_szoptions ); gpps_forced(sesskey, "zDownloadDir", "C:\\", conf, CONF_zdownloaddir ); #endif -#ifdef PERSOPORT +#ifdef MOD_PERSO gppi_forced(sesskey, "TransparencyValue", 0, conf, CONF_transparencynumber ) ; if( conf_get_int( conf, CONF_transparencynumber) < -1 ) conf_set_int( conf,CONF_transparencynumber,-1) ; if( conf_get_int( conf, CONF_transparencynumber) > 255 ) conf_set_int( conf,CONF_transparencynumber,255) ; @@ -1047,7 +1046,7 @@ void load_open_settings_forced(char *filename, Conf *conf) { gppi_forced(sesskey, "WindowState", 0, conf, CONF_windowstate ); gppb_forced(sesskey, "SaveWindowPos", false, conf, CONF_save_windowpos ); /* BKG */ gppb_forced(sesskey, "ForegroundOnBell", false, conf, CONF_foreground_on_bell ); -#ifndef NO_PASSWORD +#ifndef MOD_NOPASSWORD if( strlen(conf_get_str(conf, CONF_host))>0 ) { if( (strlen(conf_get_str(conf, CONF_host))+strlen(conf_get_str(conf, CONF_termtype))) < 1000 ) { sprintf( PassKey, "%s%sKiTTY", conf_get_str(conf, CONF_host), conf_get_str(conf, CONF_termtype) ) ; @@ -1090,13 +1089,10 @@ void load_open_settings_forced(char *filename, Conf *conf) { gpps_forced(sesskey, "Comment", "", conf, CONF_comment ); gppi_forced(sesskey, "SCPAutoPwd", 0, conf, CONF_scp_auto_pwd); #endif -#ifdef ACSPORT - gppb_forced(sesskey, "ACSinUTF", false, conf, CONF_acs_in_utf); -#endif -#ifdef PORTKNOCKINGPORT +#ifdef MOD_PORTKNOCKING gpps_forced(sesskey, "PortKnocking", "", conf, CONF_portknockingoptions ); #endif -#ifdef DISABLEALTGRPORT +#ifdef MOD_DISABLEALTGR gppi_forced(sesskey, "DisableAltGr", 0, conf, CONF_disablealtgr); #endif // END COPY/PASTE diff --git a/kitty_ssh.c b/kitty_ssh.c index 3085d80..5912c2d 100644 --- a/kitty_ssh.c +++ b/kitty_ssh.c @@ -1,7 +1,7 @@ #include "kitty_ssh.h" #include "kitty_tools.h" -#ifdef PORTKNOCKINGPORT +#ifdef MOD_PORTKNOCKING void vprint(char *fmt, ...) { char buf[1024]; va_list args; diff --git a/kitty_ssh.h b/kitty_ssh.h index 76b9734..586c074 100644 --- a/kitty_ssh.h +++ b/kitty_ssh.h @@ -1,7 +1,7 @@ #ifndef KITTY_SSH #define KITTY_SSH -#ifdef PORTKNOCKINGPORT +#ifdef MOD_PORTKNOCKING #define PROTO_TCP 1 #define PROTO_UDP 2 int knock( char *hostname, unsigned short port, unsigned short proto) ; diff --git a/kitty_win.c b/kitty_win.c index 391df92..164bd12 100644 --- a/kitty_win.c +++ b/kitty_win.c @@ -2,7 +2,7 @@ // Modifie la transparence void SetTransparency( HWND hwnd, int value ) { -#ifndef NO_TRANSPARENCY +#ifndef MOD_NOTRANSPARENCY SetLayeredWindowAttributes( hwnd, 0, value, LWA_ALPHA ) ; #endif } diff --git a/url/re_lib/regexp.c b/url/re_lib/regexp.c index ea9888e..ed843db 100644 --- a/url/re_lib/regexp.c +++ b/url/re_lib/regexp.c @@ -210,7 +210,7 @@ regcomp( char* exp) register char *longest; register int len; int flags; - int i; // Ajout HYPERLINKPORT + int i; // Ajout MOD_HYPERLINK if (exp == NULL) FAIL("NULL argument"); @@ -233,8 +233,8 @@ regcomp( char* exp) if (r == NULL) FAIL("out of space"); - for( i=0 ; istartp[i] != NULL) free( r->startp[i] ) ; r->startp[i] = NULL ; } // Ajout HYPERLINKPORT - for( i=0 ; iendp[i] != NULL) free( r->endp[i] ) ; r->endp[i] = NULL ; } // Ajout HYPERLINKPORT + for( i=0 ; istartp[i] != NULL) free( r->startp[i] ) ; r->startp[i] = NULL ; } // Ajout MOD_HYPERLINK + for( i=0 ; iendp[i] != NULL) free( r->endp[i] ) ; r->endp[i] = NULL ; } // Ajout MOD_HYPERLINK /* Second pass: emit code. */ regparse = exp; diff --git a/url/urlhack.c b/url/urlhack.c index bf98337..f6a1ed0 100644 --- a/url/urlhack.c +++ b/url/urlhack.c @@ -221,7 +221,7 @@ void set_regerror_func( void (*func)( char*)) #endif void urlhack_set_regular_expression(int mode, const char* expression) { -#ifndef NO_HYPERLINK +#ifndef MOD_NOHYPERLINK char *to_use=NULL; switch (mode) { case URLHACK_REGEX_CUSTOM: @@ -266,7 +266,7 @@ void urlhack_set_regular_expression(int mode, const char* expression) void urlhack_go_find_me_some_hyperlinks(int screen_width) { -#ifndef NO_HYPERLINK +#ifndef MOD_NOHYPERLINK char* text_pos; if( urlhack_disabled!=0 ) { diff --git a/url/urlhack.old.c b/url/urlhack.old.c index 93871e1..7d3ccf3 100644 --- a/url/urlhack.old.c +++ b/url/urlhack.old.c @@ -207,7 +207,7 @@ static void rtfm(char *error) void urlhack_set_regular_expression(int mode, const char* expression) { -#ifndef NO_HYPERLINK +#ifndef MOD_NOHYPERLINK const char *to_use=NULL; switch (mode) { case URLHACK_REGEX_CUSTOM: @@ -243,7 +243,7 @@ void urlhack_set_regular_expression(int mode, const char* expression) void urlhack_go_find_me_some_hyperlinks(int screen_width) { -#ifndef NO_HYPERLINK +#ifndef MOD_NOHYPERLINK char* text_pos; if (urlhack_disabled != 0) return; if (is_regexp_compiled == 0) { diff --git a/void.c b/void.c index d1dc0c6..56ec37d 100644 --- a/void.c +++ b/void.c @@ -5,6 +5,6 @@ #include #include "putty.h" -#ifdef PERSOPORT +#ifdef MOD_PERSO #endif diff --git a/wincrypt/wincrypto.c b/wincrypt/wincrypto.c index 1c3332e..1ca49fe 100644 --- a/wincrypt/wincrypto.c +++ b/wincrypt/wincrypto.c @@ -1,4 +1,4 @@ -#ifdef WINCRYPTPORT +#ifdef MOD_WINCRYPT #ifdef USE_CAPI /* * PuTTY wincrypt patch main file. diff --git a/wincrypt/wincrypto.h b/wincrypt/wincrypto.h index 0bb1460..dbbb42d 100644 --- a/wincrypt/wincrypto.h +++ b/wincrypt/wincrypto.h @@ -1,4 +1,4 @@ -#ifdef WINCRYPTPORT +#ifdef MOD_WINCRYPT #ifdef USE_CAPI void* capi_rsa2_sign(void *pRSAKeyStruct, char *data, int datalen); int capi_is_capikey(void *pRSAKeyStruct); diff --git a/zmodem/winpzmodem.c b/zmodem/winpzmodem.c index 305c8bf..5a4a889 100644 --- a/zmodem/winpzmodem.c +++ b/zmodem/winpzmodem.c @@ -1,4 +1,4 @@ -#ifdef ZMODEMPORT +#ifdef MOD_ZMODEM #include "putty.h" #include "terminal.h"