diff --git a/.gitattributes b/.gitattributes index d90f238..f321b56 100644 --- a/.gitattributes +++ b/.gitattributes @@ -21,3 +21,4 @@ *.sh text eol=lf config.sub text eol=lf fixalgorithms text eol=lf +runconfigure text eol=lf diff --git a/.gitignore b/.gitignore index 30b5495..904aa1f 100644 --- a/.gitignore +++ b/.gitignore @@ -254,4 +254,13 @@ regress/t6.out1 Makefile openbsd-compat/Makefile openbsd-compat/regress/Makefile -contrib/win32/win32compat/Makefile \ No newline at end of file +contrib/win32/win32compat/Makefile +config.h +config.h +regress/rsa_ssh2_cr.prv +regress/rsa_ssh2_crnl.prv +regress/t7.out.pub +regress/t6.out2 +config.h +configure +config.h \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index d27761f..0000000 --- a/Makefile +++ /dev/null @@ -1,616 +0,0 @@ -# $Id: Makefile.in,v 1.325 2011/08/05 20:15:18 djm Exp $ - -# uncomment if you run a non bourne compatable shell. Ie. csh -#SHELL = /usr/bin/sh - -AUTORECONF=autoreconf - -prefix=/usr/local -exec_prefix=${prefix} -bindir=${exec_prefix}/bin -sbindir=${exec_prefix}/sbin -libexecdir=${exec_prefix}/libexec -datadir=${datarootdir} -datarootdir=${prefix}/share -mandir=${datarootdir}/man -mansubdir=man -sysconfdir=${prefix}/etc -piddir=/var/run -srcdir=. -top_srcdir=. - -DESTDIR= - -SSH_PROGRAM=${exec_prefix}/bin/ssh -ASKPASS_PROGRAM=$(libexecdir)/ssh-askpass -SFTP_SERVER=$(libexecdir)/sftp-server -SSH_KEYSIGN=$(libexecdir)/ssh-keysign -SSH_PKCS11_HELPER=$(libexecdir)/ssh-pkcs11-helper -PRIVSEP_PATH=/var/empty -SSH_PRIVSEP_USER=sshd -STRIP_OPT=-s -TEST_SHELL=sh - -PATHS= -DSSHDIR=\"$(sysconfdir)\" \ - -D_PATH_SSH_PROGRAM=\"$(SSH_PROGRAM)\" \ - -D_PATH_SSH_ASKPASS_DEFAULT=\"$(ASKPASS_PROGRAM)\" \ - -D_PATH_SFTP_SERVER=\"$(SFTP_SERVER)\" \ - -D_PATH_SSH_KEY_SIGN=\"$(SSH_KEYSIGN)\" \ - -D_PATH_SSH_PKCS11_HELPER=\"$(SSH_PKCS11_HELPER)\" \ - -D_PATH_SSH_PIDDIR=\"$(piddir)\" \ - -D_PATH_PRIVSEP_CHROOT_DIR=\"$(PRIVSEP_PATH)\" - -CC=i686-pc-mingw32-gcc -LD=i686-pc-mingw32-gcc -CFLAGS=-g -O2 -Wall -Wpointer-arith -Wuninitialized -Wsign-compare -Wformat-security -Wno-pointer-sign -Wno-unused-result -fno-strict-aliasing -fno-builtin-memset -fstack-protector-all -I/cygdrive/c/openssh/Win32-OpenSSH/contrib/win32/win32compat/includes -I/cygdrive/c/openssh/Win32-OpenSSH/openbsd-compat -I/cygdrive/c/openssh/Win32-OpenSSH/contrib/win32/win32compat/includes -I/cygdrive/c/openssh/Win32-OpenSSH/libkrb -I/usr/local -CPPFLAGS=-I. -I$(srcdir) -I/cygdrive/c/openssh/openssl-1.0.2d/include -I/cygdrive/c/openssh/zlib-1.2.8 $(PATHS) -DHAVE_CONFIG_H -LIBS=-lcrypto -lz -lws2_32 -lgdi32 -lNetAPI32 -luserenv -lsecur32 -lshlwapi -K5LIBS=@K5LIBS@ -GSSLIBS=@GSSLIBS@ -SSHLIBS= -SSHDLIBS= -LIBEDIT= -AR=/usr/bin/ar -AWK=gawk -RANLIB=i686-pc-mingw32-ranlib -INSTALL=/usr/bin/install -c -PERL=/usr/bin/perl -SED=/usr/bin/sed -ENT= -XAUTH_PATH=undefined -LDFLAGS=-L. -Lopenbsd-compat/ -Lcontrib/win32/win32compat -L/cygdrive/c/openssh/openssl-1.0.2d -L/cygdrive/c/openssh/zlib-1.2.8 -fstack-protector-all -EXEEXT=.exe -MANFMT=/usr/bin/nroff -mandoc - -TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-keysign${EXEEXT} ssh-pkcs11-helper$(EXEEXT) ssh-agent$(EXEEXT) sftp-server$(EXEEXT) sftp$(EXEEXT) - -LIBOPENSSH_OBJS=\ - ssh_api.o \ - ssherr.o \ - sshbuf.o \ - sshkey.o \ - sshbuf-getput-basic.o \ - sshbuf-misc.o \ - sshbuf-getput-crypto.o \ - krl.o \ - bitmap.o - -LIBSSH_OBJS=${LIBOPENSSH_OBJS} \ - authfd.o authfile.o bufaux.o bufbn.o bufec.o buffer.o \ - canohost.o channels.o cipher.o cipher-aes.o cipher-aesctr.o \ - cipher-bf1.o cipher-ctr.o cipher-3des1.o cleanup.o \ - compat.o crc32.o deattack.o fatal.o hostfile.o \ - log.o match.o md-sha256.o moduli.o nchan.o packet.o opacket.o \ - readpass.o rsa.o ttymodes.o xmalloc.o addrmatch.o \ - atomicio.o key.o dispatch.o mac.o uidswap.o uuencode.o misc.o \ - monitor_fdpass.o rijndael.o ssh-dss.o ssh-ecdsa.o ssh-rsa.o dh.o \ - msg.o progressmeter.o dns.o entropy.o gss-genr.o umac.o umac128.o \ - ssh-pkcs11.o smult_curve25519_ref.o \ - poly1305.o chacha.o cipher-chachapoly.o \ - ssh-ed25519.o digest-openssl.o digest-libc.o hmac.o \ - sc25519.o ge25519.o fe25519.o ed25519.o verify.o hash.o blocks.o \ - kex.o kexdh.o kexgex.o kexecdh.o kexc25519.o \ - kexdhc.o kexgexc.o kexecdhc.o kexc25519c.o \ - kexdhs.o kexgexs.o kexecdhs.o kexc25519s.o \ - kerberos-sspi.o schnorr.o jpake.o - -SSHOBJS= ssh.o readconf.o clientloop.o sshtty.o \ - sshconnect.o sshconnect1.o sshconnect2.o mux.o \ - roaming_common.o roaming_client.o - -SSHDOBJS=sshd.o auth-rhosts.o auth-passwd.o auth-rsa.o auth-rh-rsa.o \ - audit.o audit-bsm.o audit-linux.o platform.o \ - sshpty.o sshlogin.o servconf.o serverloop.o \ - auth.o auth1.o auth2.o auth-options.o session.o \ - auth-chall.o auth2-chall.o groupaccess.o \ - auth-skey.o auth-bsdauth.o auth2-hostbased.o auth2-kbdint.o \ - auth2-none.o auth2-passwd.o auth2-pubkey.o \ - monitor_mm.o monitor.o monitor_wrap.o auth-krb5.o \ - auth2-gss.o gss-serv.o gss-serv-krb5.o \ - loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o \ - sftp-server.o sftp-common.o \ - roaming_common.o roaming_serv.o \ - sandbox-null.o sandbox-rlimit.o sandbox-systrace.o sandbox-darwin.o \ - sandbox-seccomp-filter.o sandbox-capsicum.o \ - pam.o kexdhs.o kexgexs.o kexecdhs.o - -MANPAGES = moduli.5.out scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out ssh-keysign.8.out ssh-pkcs11-helper.8.out sshd_config.5.out ssh_config.5.out -MANPAGES_IN = moduli.5 scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8 sftp.1 ssh-keysign.8 ssh-pkcs11-helper.8 sshd_config.5 ssh_config.5 -MANTYPE = doc - -CONFIGFILES=sshd_config.out ssh_config.out moduli.out -CONFIGFILES_IN=sshd_config ssh_config moduli - -PATHSUBS = \ - -e 's|/etc/ssh/ssh_config|$(sysconfdir)/ssh_config|g' \ - -e 's|/etc/ssh/ssh_known_hosts|$(sysconfdir)/ssh_known_hosts|g' \ - -e 's|/etc/ssh/sshd_config|$(sysconfdir)/sshd_config|g' \ - -e 's|/usr/libexec|$(libexecdir)|g' \ - -e 's|/etc/shosts.equiv|$(sysconfdir)/shosts.equiv|g' \ - -e 's|/etc/ssh/ssh_host_key|$(sysconfdir)/ssh_host_key|g' \ - -e 's|/etc/ssh/ssh_host_ecdsa_key|$(sysconfdir)/ssh_host_ecdsa_key|g' \ - -e 's|/etc/ssh/ssh_host_dsa_key|$(sysconfdir)/ssh_host_dsa_key|g' \ - -e 's|/etc/ssh/ssh_host_rsa_key|$(sysconfdir)/ssh_host_rsa_key|g' \ - -e 's|/etc/ssh/ssh_host_ed25519_key|$(sysconfdir)/ssh_host_ed25519_key|g' \ - -e 's|/var/run/sshd.pid|$(piddir)/sshd.pid|g' \ - -e 's|/etc/moduli|$(sysconfdir)/moduli|g' \ - -e 's|/etc/ssh/moduli|$(sysconfdir)/moduli|g' \ - -e 's|/etc/ssh/sshrc|$(sysconfdir)/sshrc|g' \ - -e 's|/usr/X11R6/bin/xauth|$(XAUTH_PATH)|g' \ - -e 's|/var/empty|$(PRIVSEP_PATH)|g' \ - -e 's|/usr/bin:/bin:/usr/sbin:/sbin|/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin|g' - -FIXPATHSCMD = $(SED) $(PATHSUBS) -FIXALGORITHMSCMD= $(SHELL) $(srcdir)/fixalgorithms $(SED) \ - @UNSUPPORTED_ALGORITHMS@ - -all: $(CONFIGFILES) $(MANPAGES) $(TARGETS) - -$(LIBSSH_OBJS): Makefile.in config.h -$(SSHOBJS): Makefile.in config.h -$(SSHDOBJS): Makefile.in config.h - -.c.o: - $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ - -LIBWIN32COMPAT=contrib/win32/win32compat/libwin32compat.a -$(LIBWIN32COMPAT): always - (cd contrib/win32/win32compat && $(MAKE)) - -LIBCOMPAT=openbsd-compat/libopenbsd-compat.a -$(LIBCOMPAT): always - (cd openbsd-compat && $(MAKE)) -always: - -libssh.a: $(LIBSSH_OBJS) - $(AR) rv $@ $(LIBSSH_OBJS) - $(RANLIB) $@ - -ssh$(EXEEXT): $(LIBCOMPAT) libssh.a contrib/win32/win32compat/libwin32compat.a $(SSHOBJS) - $(LD) -o $@ $(SSHOBJS) $(LDFLAGS) ./libssh.a -lopenbsd-compat $(SSHLIBS) -lwin32compat $(LIBS) - -sshd$(EXEEXT): libssh.a contrib/win32/win32compat/libwin32compat.a $(LIBCOMPAT) $(SSHDOBJS) - $(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) ./libssh.a -lopenbsd-compat -lwin32compat $(SSHDLIBS) $(LIBS) - -ssh-add$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-add.o contrib/win32/win32compat/libwin32compat.a - $(LD) -o $@ ssh-add.o $(LDFLAGS) ./libssh.a -lopenbsd-compat -lwin32compat $(LIBS) - -ssh-agent$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-agent.o ssh-pkcs11-client.o contrib/win32/win32compat/libwin32compat.a - $(LD) -o $@ ssh-agent.o ssh-pkcs11-client.o $(LDFLAGS) ./libssh.a -lopenbsd-compat -lwin32compat $(LIBS) - -ssh-keygen$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keygen.o contrib/win32/win32compat/libwin32compat.a - $(LD) -o $@ ssh-keygen.o $(LDFLAGS) ./libssh.a -lopenbsd-compat -lwin32compat $(LIBS) - -ssh-keysign$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keysign.o roaming_dummy.o readconf.o contrib/win32/win32compat/libwin32compat.a - $(LD) -o $@ ssh-keysign.o readconf.o roaming_dummy.o $(LDFLAGS) ./libssh.a -lopenbsd-compat -lwin32compat $(LIBS) - -ssh-pkcs11-helper$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-pkcs11-helper.o ssh-pkcs11.o contrib/win32/win32compat/libwin32compat.a - $(LD) -o $@ ssh-pkcs11-helper.o ssh-pkcs11.o $(LDFLAGS) ./libssh.a -lopenbsd-compat -lopenbsd-compat -lwin32compat $(LIBS) - -ssh-keyscan$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keyscan.o roaming_dummy.o contrib/win32/win32compat/libwin32compat.a - $(LD) -o $@ ssh-keyscan.o roaming_dummy.o $(LDFLAGS) ./libssh.a -lopenbsd-compat -lwin32compat $(LIBS) - -sftp-server$(EXEEXT): $(LIBCOMPAT) libssh.a sftp.o sftp-common.o sftp-server.o sftp-server-main.o contrib/win32/win32compat/libwin32compat.a - $(LD) -o $@ sftp-server.o sftp-common.o sftp-server-main.o $(LDFLAGS) ./libssh.a -lopenbsd-compat -lwin32compat $(LIBS) - -sftp$(EXEEXT): $(LIBCOMPAT) libssh.a sftp.o sftp-client.o sftp-common.o sftp-glob.o progressmeter.o contrib/win32/win32compat/libwin32compat.a - $(LD) -o $@ progressmeter.o sftp.o sftp-client.o sftp-common.o sftp-glob.o $(LDFLAGS) ./libssh.a -lopenbsd-compat -lwin32compat $(LIBS) $(LIBEDIT) - -# test driver for the loginrec code - not built by default -logintest: logintest.o $(LIBCOMPAT) libssh.a loginrec.o contrib/win32/win32compat/libwin32compat.a - $(LD) -o $@ logintest.o $(LDFLAGS) loginrec.o -lopenbsd-compat ./libssh.a -lwin32compat $(LIBS) - -$(MANPAGES): $(MANPAGES_IN) - if test "$(MANTYPE)" = "cat"; then \ - manpage=$(srcdir)/`echo $@ | sed 's/\.[1-9]\.out$$/\.0/'`; \ - else \ - manpage=$(srcdir)/`echo $@ | sed 's/\.out$$//'`; \ - fi; \ - if test "$(MANTYPE)" = "man"; then \ - $(FIXPATHSCMD) $${manpage} | $(FIXALGORITHMSCMD) | \ - $(AWK) -f $(srcdir)/mdoc2man.awk > $@; \ - else \ - $(FIXPATHSCMD) $${manpage} | $(FIXALGORITHMSCMD) > $@; \ - fi - -$(CONFIGFILES): $(CONFIGFILES_IN) - conffile=`echo $@ | sed 's/.out$$//'`; \ - $(FIXPATHSCMD) $(srcdir)/$${conffile} > $@ - -# fake rule to stop make trying to compile moduli.o into a binary "moduli.o" -moduli: - echo - -# special case target for umac128 -umac128.o: umac.c - $(CC) $(CFLAGS) $(CPPFLAGS) -o umac128.o -c $(srcdir)/umac.c \ - -DUMAC_OUTPUT_LEN=16 -Dumac_new=umac128_new \ - -Dumac_update=umac128_update -Dumac_final=umac128_final \ - -Dumac_delete=umac128_delete - -clean: regressclean - rm -f *.o *.a $(TARGETS) logintest config.cache config.log - rm -f *.out core survey - rm -f regress/unittests/test_helper/*.a - rm -f regress/unittests/test_helper/*.o - rm -f regress/unittests/sshbuf/*.o - rm -f regress/unittests/sshbuf/test_sshbuf - rm -f regress/unittests/sshkey/*.o - rm -f regress/unittests/sshkey/test_sshkey - rm -f regress/unittests/bitmap/*.o - rm -f regress/unittests/bitmap/test_bitmap - rm -f regress/unittests/hostkeys/*.o - rm -f regress/unittests/hostkeys/test_hostkeys - rm -f regress/unittests/kex/*.o - rm -f regress/unittests/kex/test_kex - (cd openbsd-compat && $(MAKE) clean) - if test -f contrib/win32/win32compat/Makefile ; then \ - (cd contrib/win32/win32compat && $(MAKE) clean) \ - fi - -distclean: regressclean - rm -f *.o *.a $(TARGETS) logintest config.cache config.log - rm -f *.out core opensshd.init openssh.xml - rm -f Makefile buildpkg.sh config.h config.status - rm -f survey.sh openbsd-compat/regress/Makefile *~ - rm -rf autom4te.cache - rm -f regress/unittests/test_helper/*.a - rm -f regress/unittests/test_helper/*.o - rm -f regress/unittests/sshbuf/*.o - rm -f regress/unittests/sshbuf/test_sshbuf - rm -f regress/unittests/sshkey/*.o - rm -f regress/unittests/sshkey/test_sshkey - rm -f regress/unittests/bitmap/*.o - rm -f regress/unittests/bitmap/test_bitmap - rm -f regress/unittests/hostkeys/*.o - rm -f regress/unittests/hostkeys/test_hostkeys - rm -f regress/unittests/kex/*.o - rm -f regress/unittests/kex/test_kex - (cd openbsd-compat && $(MAKE) distclean) - if test -f contrib/win32/win32compat/Makefile ; then \ - (cd contrib/win32/win32compat && $(MAKE) distclean) \ - fi - if test -d pkg ; then \ - rm -fr pkg ; \ - fi - -veryclean: distclean - rm -f configure config.h.in *.0 - -cleandir: veryclean - -mrproper: veryclean - -realclean: veryclean - -catman-do: - @for f in $(MANPAGES_IN) ; do \ - base=`echo $$f | sed 's/\..*$$//'` ; \ - echo "$$f -> $$base.0" ; \ - $(MANFMT) $$f | cat -v | sed -e 's/.\^H//g' \ - >$$base.0 ; \ - done - -distprep: catman-do - $(AUTORECONF) - -rm -rf autom4te.cache - -install: $(CONFIGFILES) $(MANPAGES) $(TARGETS) install-files install-sysconf host-key check-config -install-nokeys: $(CONFIGFILES) $(MANPAGES) $(TARGETS) install-files install-sysconf -install-nosysconf: $(CONFIGFILES) $(MANPAGES) $(TARGETS) install-files - -check-config: - -$(DESTDIR)$(sbindir)/sshd -t -f $(DESTDIR)$(sysconfdir)/sshd_config - -install-files: - $(srcdir)/mkinstalldirs $(DESTDIR)$(bindir) - $(srcdir)/mkinstalldirs $(DESTDIR)$(sbindir) - $(srcdir)/mkinstalldirs $(DESTDIR)$(mandir) - $(srcdir)/mkinstalldirs $(DESTDIR)$(mandir)/$(mansubdir)1 - $(srcdir)/mkinstalldirs $(DESTDIR)$(mandir)/$(mansubdir)5 - $(srcdir)/mkinstalldirs $(DESTDIR)$(mandir)/$(mansubdir)8 - $(srcdir)/mkinstalldirs $(DESTDIR)$(libexecdir) - (umask 022 ; $(srcdir)/mkinstalldirs $(DESTDIR)$(PRIVSEP_PATH)) - $(INSTALL) -m 0755 $(STRIP_OPT) ssh$(EXEEXT) $(DESTDIR)$(bindir)/ssh$(EXEEXT) - $(INSTALL) -m 0755 $(STRIP_OPT) scp$(EXEEXT) $(DESTDIR)$(bindir)/scp$(EXEEXT) - $(INSTALL) -m 0755 $(STRIP_OPT) ssh-add$(EXEEXT) $(DESTDIR)$(bindir)/ssh-add$(EXEEXT) - $(INSTALL) -m 0755 $(STRIP_OPT) ssh-agent$(EXEEXT) $(DESTDIR)$(bindir)/ssh-agent$(EXEEXT) - $(INSTALL) -m 0755 $(STRIP_OPT) ssh-keygen$(EXEEXT) $(DESTDIR)$(bindir)/ssh-keygen$(EXEEXT) - $(INSTALL) -m 0755 $(STRIP_OPT) ssh-keyscan$(EXEEXT) $(DESTDIR)$(bindir)/ssh-keyscan$(EXEEXT) - $(INSTALL) -m 0755 $(STRIP_OPT) sshd$(EXEEXT) $(DESTDIR)$(sbindir)/sshd$(EXEEXT) - $(INSTALL) -m 4711 $(STRIP_OPT) ssh-keysign$(EXEEXT) $(DESTDIR)$(SSH_KEYSIGN)$(EXEEXT) - $(INSTALL) -m 0755 $(STRIP_OPT) ssh-pkcs11-helper$(EXEEXT) $(DESTDIR)$(SSH_PKCS11_HELPER)$(EXEEXT) - $(INSTALL) -m 0755 $(STRIP_OPT) sftp$(EXEEXT) $(DESTDIR)$(bindir)/sftp$(EXEEXT) - $(INSTALL) -m 0755 $(STRIP_OPT) sftp-server$(EXEEXT) $(DESTDIR)$(SFTP_SERVER)$(EXEEXT) - $(INSTALL) -m 644 ssh.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh.1 - $(INSTALL) -m 644 scp.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/scp.1 - $(INSTALL) -m 644 ssh-add.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-add.1 - $(INSTALL) -m 644 ssh-agent.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-agent.1 - $(INSTALL) -m 644 ssh-keygen.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-keygen.1 - $(INSTALL) -m 644 ssh-keyscan.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-keyscan.1 - $(INSTALL) -m 644 moduli.5.out $(DESTDIR)$(mandir)/$(mansubdir)5/moduli.5 - $(INSTALL) -m 644 sshd_config.5.out $(DESTDIR)$(mandir)/$(mansubdir)5/sshd_config.5 - $(INSTALL) -m 644 ssh_config.5.out $(DESTDIR)$(mandir)/$(mansubdir)5/ssh_config.5 - $(INSTALL) -m 644 sshd.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/sshd.8 - $(INSTALL) -m 644 sftp.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/sftp.1 - $(INSTALL) -m 644 sftp-server.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/sftp-server.8 - $(INSTALL) -m 644 ssh-keysign.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-keysign.8 - $(INSTALL) -m 644 ssh-pkcs11-helper.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-pkcs11-helper.8 - -rm -f $(DESTDIR)$(bindir)/slogin - ln -s ./ssh$(EXEEXT) $(DESTDIR)$(bindir)/slogin - -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/slogin.1 - ln -s ./ssh.1 $(DESTDIR)$(mandir)/$(mansubdir)1/slogin.1 - -install-sysconf: - if [ ! -d $(DESTDIR)$(sysconfdir) ]; then \ - $(srcdir)/mkinstalldirs $(DESTDIR)$(sysconfdir); \ - fi - @if [ ! -f $(DESTDIR)$(sysconfdir)/ssh_config ]; then \ - $(INSTALL) -m 644 ssh_config.out $(DESTDIR)$(sysconfdir)/ssh_config; \ - else \ - echo "$(DESTDIR)$(sysconfdir)/ssh_config already exists, install will not overwrite"; \ - fi - @if [ ! -f $(DESTDIR)$(sysconfdir)/sshd_config ]; then \ - $(INSTALL) -m 644 sshd_config.out $(DESTDIR)$(sysconfdir)/sshd_config; \ - else \ - echo "$(DESTDIR)$(sysconfdir)/sshd_config already exists, install will not overwrite"; \ - fi - @if [ ! -f $(DESTDIR)$(sysconfdir)/moduli ]; then \ - if [ -f $(DESTDIR)$(sysconfdir)/primes ]; then \ - echo "moving $(DESTDIR)$(sysconfdir)/primes to $(DESTDIR)$(sysconfdir)/moduli"; \ - mv "$(DESTDIR)$(sysconfdir)/primes" "$(DESTDIR)$(sysconfdir)/moduli"; \ - else \ - $(INSTALL) -m 644 moduli.out $(DESTDIR)$(sysconfdir)/moduli; \ - fi ; \ - else \ - echo "$(DESTDIR)$(sysconfdir)/moduli already exists, install will not overwrite"; \ - fi - -host-key: ssh-keygen$(EXEEXT) - @if [ -z "$(DESTDIR)" ] ; then \ - if [ -f "$(sysconfdir)/ssh_host_key" ] ; then \ - echo "$(sysconfdir)/ssh_host_key already exists, skipping." ; \ - else \ - ./ssh-keygen -t rsa1 -f $(sysconfdir)/ssh_host_key -N "" ; \ - fi ; \ - if [ -f $(sysconfdir)/ssh_host_dsa_key ] ; then \ - echo "$(sysconfdir)/ssh_host_dsa_key already exists, skipping." ; \ - else \ - ./ssh-keygen -t dsa -f $(sysconfdir)/ssh_host_dsa_key -N "" ; \ - fi ; \ - if [ -f $(sysconfdir)/ssh_host_rsa_key ] ; then \ - echo "$(sysconfdir)/ssh_host_rsa_key already exists, skipping." ; \ - else \ - ./ssh-keygen -t rsa -f $(sysconfdir)/ssh_host_rsa_key -N "" ; \ - fi ; \ - if [ -f $(sysconfdir)/ssh_host_ed25519_key ] ; then \ - echo "$(sysconfdir)/ssh_host_ed25519_key already exists, skipping." ; \ - else \ - ./ssh-keygen -t ed25519 -f $(sysconfdir)/ssh_host_ed25519_key -N "" ; \ - fi ; \ - if [ -z "" ] ; then \ - if [ -f $(sysconfdir)/ssh_host_ecdsa_key ] ; then \ - echo "$(sysconfdir)/ssh_host_ecdsa_key already exists, skipping." ; \ - else \ - ./ssh-keygen -t ecdsa -f $(sysconfdir)/ssh_host_ecdsa_key -N "" ; \ - fi ; \ - fi ; \ - fi ; - -host-key-force: ssh-keygen$(EXEEXT) - ./ssh-keygen -t rsa1 -f $(DESTDIR)$(sysconfdir)/ssh_host_key -N "" - ./ssh-keygen -t dsa -f $(DESTDIR)$(sysconfdir)/ssh_host_dsa_key -N "" - ./ssh-keygen -t rsa -f $(DESTDIR)$(sysconfdir)/ssh_host_rsa_key -N "" - ./ssh-keygen -t ed25519 -f $(DESTDIR)$(sysconfdir)/ssh_host_ed25519_key -N "" - test -z "" && ./ssh-keygen -t ecdsa -f $(DESTDIR)$(sysconfdir)/ssh_host_ecdsa_key -N "" - -uninstallall: uninstall - -rm -f $(DESTDIR)$(sysconfdir)/ssh_config - -rm -f $(DESTDIR)$(sysconfdir)/sshd_config - -rmdir $(DESTDIR)$(sysconfdir) - -rmdir $(DESTDIR)$(bindir) - -rmdir $(DESTDIR)$(sbindir) - -rmdir $(DESTDIR)$(mandir)/$(mansubdir)1 - -rmdir $(DESTDIR)$(mandir)/$(mansubdir)8 - -rmdir $(DESTDIR)$(mandir) - -rmdir $(DESTDIR)$(libexecdir) - -uninstall: - -rm -f $(DESTDIR)$(bindir)/slogin - -rm -f $(DESTDIR)$(bindir)/ssh$(EXEEXT) - -rm -f $(DESTDIR)$(bindir)/scp$(EXEEXT) - -rm -f $(DESTDIR)$(bindir)/ssh-add$(EXEEXT) - -rm -f $(DESTDIR)$(bindir)/ssh-agent$(EXEEXT) - -rm -f $(DESTDIR)$(bindir)/ssh-keygen$(EXEEXT) - -rm -f $(DESTDIR)$(bindir)/ssh-keyscan$(EXEEXT) - -rm -f $(DESTDIR)$(bindir)/sftp$(EXEEXT) - -rm -f $(DESTDIR)$(sbindir)/sshd$(EXEEXT) - -rm -r $(DESTDIR)$(SFTP_SERVER)$(EXEEXT) - -rm -f $(DESTDIR)$(SSH_KEYSIGN)$(EXEEXT) - -rm -f $(DESTDIR)$(SSH_PKCS11_HELPER)$(EXEEXT) - -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/ssh.1 - -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/scp.1 - -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-add.1 - -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-agent.1 - -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-keygen.1 - -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/sftp.1 - -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-keyscan.1 - -rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/sshd.8 - -rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/sftp-server.8 - -rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-keysign.8 - -rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-pkcs11-helper.8 - -rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/slogin.1 - -regress-prep: - [ -d `pwd`/regress ] || mkdir -p `pwd`/regress - [ -d `pwd`/regress/unittests ] || mkdir -p `pwd`/regress/unittests - [ -d `pwd`/regress/unittests/test_helper ] || \ - mkdir -p `pwd`/regress/unittests/test_helper - [ -d `pwd`/regress/unittests/sshbuf ] || \ - mkdir -p `pwd`/regress/unittests/sshbuf - [ -d `pwd`/regress/unittests/sshkey ] || \ - mkdir -p `pwd`/regress/unittests/sshkey - [ -d `pwd`/regress/unittests/bitmap ] || \ - mkdir -p `pwd`/regress/unittests/bitmap - [ -d `pwd`/regress/unittests/hostkeys ] || \ - mkdir -p `pwd`/regress/unittests/hostkeys - [ -d `pwd`/regress/unittests/kex ] || \ - mkdir -p `pwd`/regress/unittests/kex - [ -f `pwd`/regress/Makefile ] || \ - ln -s `cd $(srcdir) && pwd`/regress/Makefile `pwd`/regress/Makefile - -regress/modpipe$(EXEEXT): $(srcdir)/regress/modpipe.c - $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $? \ - $(LDFLAGS) ./libssh.a -lopenbsd-compat -lwin32compat $(LIBS) - -regress/setuid-allowed$(EXEEXT): $(srcdir)/regress/setuid-allowed.c - $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $? \ - $(LDFLAGS) ./libssh.a -lopenbsd-compat -lwin32compat $(LIBS) - -regress/netcat$(EXEEXT): $(srcdir)/regress/netcat.c - $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $? \ - $(LDFLAGS) ./libssh.a -lopenbsd-compat -lwin32compat $(LIBS) - -UNITTESTS_TEST_HELPER_OBJS=\ - regress/unittests/test_helper/test_helper.o \ - regress/unittests/test_helper/fuzz.o - -regress/unittests/test_helper/libtest_helper.a: ${UNITTESTS_TEST_HELPER_OBJS} - $(AR) rv $@ $(UNITTESTS_TEST_HELPER_OBJS) - $(RANLIB) $@ - -UNITTESTS_TEST_SSHBUF_OBJS=\ - regress/unittests/sshbuf/tests.o \ - regress/unittests/sshbuf/test_sshbuf.o \ - regress/unittests/sshbuf/test_sshbuf_getput_basic.o \ - regress/unittests/sshbuf/test_sshbuf_getput_crypto.o \ - regress/unittests/sshbuf/test_sshbuf_misc.o \ - regress/unittests/sshbuf/test_sshbuf_fuzz.o \ - regress/unittests/sshbuf/test_sshbuf_getput_fuzz.o \ - regress/unittests/sshbuf/test_sshbuf_fixed.o - -regress/unittests/sshbuf/test_sshbuf$(EXEEXT): ${UNITTESTS_TEST_SSHBUF_OBJS} \ - regress/unittests/test_helper/libtest_helper.a libssh.a - $(LD) -o $@ $(LDFLAGS) $(UNITTESTS_TEST_SSHBUF_OBJS) \ - regress/unittests/test_helper/libtest_helper.a \ - ./libssh.a -lopenbsd-compat -lwin32compat $(LIBS) - -UNITTESTS_TEST_SSHKEY_OBJS=\ - regress/unittests/sshkey/test_fuzz.o \ - regress/unittests/sshkey/tests.o \ - regress/unittests/sshkey/common.o \ - regress/unittests/sshkey/test_file.o \ - regress/unittests/sshkey/test_sshkey.o - -regress/unittests/sshkey/test_sshkey$(EXEEXT): ${UNITTESTS_TEST_SSHKEY_OBJS} \ - regress/unittests/test_helper/libtest_helper.a libssh.a - $(LD) -o $@ $(LDFLAGS) $(UNITTESTS_TEST_SSHKEY_OBJS) \ - regress/unittests/test_helper/libtest_helper.a \ - ./libssh.a -lopenbsd-compat -lwin32compat $(LIBS) - -UNITTESTS_TEST_BITMAP_OBJS=\ - regress/unittests/bitmap/tests.o - -regress/unittests/bitmap/test_bitmap$(EXEEXT): ${UNITTESTS_TEST_BITMAP_OBJS} \ - regress/unittests/test_helper/libtest_helper.a libssh.a - $(LD) -o $@ $(LDFLAGS) $(UNITTESTS_TEST_BITMAP_OBJS) \ - regress/unittests/test_helper/libtest_helper.a \ - ./libssh.a -lopenbsd-compat -lwin32compat $(LIBS) - -UNITTESTS_TEST_KEX_OBJS=\ - regress/unittests/kex/tests.o \ - regress/unittests/kex/test_kex.o \ - roaming_dummy.o - -regress/unittests/kex/test_kex$(EXEEXT): ${UNITTESTS_TEST_KEX_OBJS} \ - regress/unittests/test_helper/libtest_helper.a libssh.a - $(LD) -o $@ $(LDFLAGS) $(UNITTESTS_TEST_KEX_OBJS) \ - regress/unittests/test_helper/libtest_helper.a \ - ./libssh.a -lopenbsd-compat -lwin32compat $(LIBS) - -UNITTESTS_TEST_HOSTKEYS_OBJS=\ - regress/unittests/hostkeys/tests.o \ - regress/unittests/hostkeys/test_iterate.o - -regress/unittests/hostkeys/test_hostkeys$(EXEEXT): \ - ${UNITTESTS_TEST_HOSTKEYS_OBJS} \ - regress/unittests/test_helper/libtest_helper.a libssh.a - $(LD) -o $@ $(LDFLAGS) $(UNITTESTS_TEST_HOSTKEYS_OBJS) \ - regress/unittests/test_helper/libtest_helper.a \ - ./libssh.a -lopenbsd-compat -lwin32compat $(LIBS) - -REGRESS_BINARIES=\ - regress/modpipe$(EXEEXT) \ - regress/setuid-allowed$(EXEEXT) \ - regress/netcat$(EXEEXT) \ - regress/unittests/sshbuf/test_sshbuf$(EXEEXT) \ - regress/unittests/sshkey/test_sshkey$(EXEEXT) \ - regress/unittests/bitmap/test_bitmap$(EXEEXT) \ - regress/unittests/hostkeys/test_hostkeys$(EXEEXT) \ - regress/unittests/kex/test_kex$(EXEEXT) - -tests interop-tests t-exec: regress-prep $(TARGETS) $(REGRESS_BINARIES) - BUILDDIR=`pwd`; \ - TEST_SSH_SCP="$${BUILDDIR}/scp"; \ - TEST_SSH_SSH="$${BUILDDIR}/ssh"; \ - TEST_SSH_SSHD="$${BUILDDIR}/sshd"; \ - TEST_SSH_SSHAGENT="$${BUILDDIR}/ssh-agent"; \ - TEST_SSH_SSHADD="$${BUILDDIR}/ssh-add"; \ - TEST_SSH_SSHKEYGEN="$${BUILDDIR}/ssh-keygen"; \ - TEST_SSH_SSHPKCS11HELPER="$${BUILDDIR}/ssh-pkcs11-helper"; \ - TEST_SSH_SSHKEYSCAN="$${BUILDDIR}/ssh-keyscan"; \ - TEST_SSH_SFTP="$${BUILDDIR}/sftp"; \ - TEST_SSH_SFTPSERVER="$${BUILDDIR}/sftp-server"; \ - TEST_SSH_PLINK="plink"; \ - TEST_SSH_PUTTYGEN="puttygen"; \ - TEST_SSH_CONCH="conch"; \ - TEST_SSH_IPV6="no" ; \ - TEST_SSH_ECC="yes" ; \ - cd $(srcdir)/regress || exit $$?; \ - $(MAKE) \ - .OBJDIR="$${BUILDDIR}/regress" \ - .CURDIR="`pwd`" \ - BUILDDIR="$${BUILDDIR}" \ - OBJ="$${BUILDDIR}/regress/" \ - PATH="$${BUILDDIR}:$${PATH}" \ - TEST_ENV=MALLOC_OPTIONS="@TEST_MALLOC_OPTIONS@" \ - TEST_SSH_SCP="$${TEST_SSH_SCP}" \ - TEST_SSH_SSH="$${TEST_SSH_SSH}" \ - TEST_SSH_SSHD="$${TEST_SSH_SSHD}" \ - TEST_SSH_SSHAGENT="$${TEST_SSH_SSHAGENT}" \ - TEST_SSH_SSHADD="$${TEST_SSH_SSHADD}" \ - TEST_SSH_SSHKEYGEN="$${TEST_SSH_SSHKEYGEN}" \ - TEST_SSH_SSHPKCS11HELPER="$${TEST_SSH_SSHPKCS11HELPER}" \ - TEST_SSH_SSHKEYSCAN="$${TEST_SSH_SSHKEYSCAN}" \ - TEST_SSH_SFTP="$${TEST_SSH_SFTP}" \ - TEST_SSH_SFTPSERVER="$${TEST_SSH_SFTPSERVER}" \ - TEST_SSH_PLINK="$${TEST_SSH_PLINK}" \ - TEST_SSH_PUTTYGEN="$${TEST_SSH_PUTTYGEN}" \ - TEST_SSH_CONCH="$${TEST_SSH_CONCH}" \ - TEST_SSH_IPV6="$${TEST_SSH_IPV6}" \ - TEST_SSH_ECC="$${TEST_SSH_ECC}" \ - TEST_SHELL="${TEST_SHELL}" \ - EXEEXT="$(EXEEXT)" \ - $@ && echo all tests passed - -compat-tests: $(LIBCOMPAT) - (cd openbsd-compat/regress && $(MAKE)) - -regressclean: - if [ -f regress/Makefile ] && [ -r regress/Makefile ]; then \ - (cd regress && $(MAKE) clean) \ - fi - -survey: survey.sh ssh - @$(SHELL) ./survey.sh > survey - @echo 'The survey results have been placed in the file "survey" in the' - @echo 'current directory. Please review the file then send with' - @echo '"make send-survey".' - -send-survey: survey - mail portable-survey@mindrot.org local_window -= win_len; } - #ifdef WIN32_FIXME - if ( (c->client_tty) && (data_len >= 5) ) { - if ( data[0] == '\033' ) { // escape char octal 33, decimal 27 - if ( (data[1] == '[') && (data[2]== '2') && (data[3]== '0') && ( data[4]== 'h' )) { - lftocrlf = 1; - data = data + 5 ; // we have processed the 5 bytes ESC sequence - data_len = data_len - 5; - } - } - } - #endif - if (c->datagram) buffer_put_string(&c->output, data, data_len); else { #ifndef WIN32_FIXME buffer_append(&c->output, data, data_len); #else - buffer_append(&c->output, data, data_len); + if ( c->client_tty ) + telProcessNetwork ( data, data_len ); // run it by ANSI engine if it is the ssh client + else + buffer_append(&c->output, data, data_len); // it is the sshd server, so pass it on if ( c->isatty ) { buffer_append(&c->input, data, data_len); // we echo the data if it is sshd server and pty interactive mode if ( (data_len ==1) && (data[0] == '\b') ) diff --git a/cipher.c b/cipher.c index 02dae6f..09a0580 100644 --- a/cipher.c +++ b/cipher.c @@ -34,7 +34,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - + #include "includes.h" #include @@ -43,6 +43,7 @@ #include #include + #include "cipher.h" #include "misc.h" #include "sshbuf.h" @@ -51,6 +52,12 @@ #include "openbsd-compat/openssl-compat.h" + + +#ifdef USE_MSCNG +#undef WITH_OPENSSL +#endif + #ifdef WITH_SSH1 extern const EVP_CIPHER *evp_ssh1_bf(void); extern const EVP_CIPHER *evp_ssh1_3des(void); @@ -108,9 +115,19 @@ static const struct sshcipher ciphers[] = { SSH_CIPHER_SSH2, 16, 32, 12, 16, 0, 0, EVP_aes_256_gcm }, # endif /* OPENSSL_HAVE_EVPGCM */ #else /* WITH_OPENSSL */ + +#ifdef USE_MSCNG + { "aes128-ctr", SSH_CIPHER_SSH2, 16, 16, 0, 0, 0, _CNG_CIPHER_AES | _CNG_MODE_CTR, NULL }, + { "aes192-ctr", SSH_CIPHER_SSH2, 16, 24, 0, 0, 0, _CNG_CIPHER_AES | _CNG_MODE_CTR, NULL }, + { "aes256-ctr", SSH_CIPHER_SSH2, 16, 32, 0, 0, 0, _CNG_CIPHER_AES | _CNG_MODE_CTR, NULL }, + { "aes128-cbc", SSH_CIPHER_SSH2, 16, 16, 0, 0, 0, _CNG_CIPHER_AES | _CNG_MODE_CBC, NULL }, + { "aes192-cbc", SSH_CIPHER_SSH2, 16, 24, 0, 0, 0, _CNG_CIPHER_AES | _CNG_MODE_CBC, NULL }, + { "aes256-cbc", SSH_CIPHER_SSH2, 16, 32, 0, 0, 0, _CNG_CIPHER_AES | _CNG_MODE_CBC, NULL }, +#else { "aes128-ctr", SSH_CIPHER_SSH2, 16, 16, 0, 0, 0, CFLAG_AESCTR, NULL }, { "aes192-ctr", SSH_CIPHER_SSH2, 16, 24, 0, 0, 0, CFLAG_AESCTR, NULL }, { "aes256-ctr", SSH_CIPHER_SSH2, 16, 32, 0, 0, 0, CFLAG_AESCTR, NULL }, +#endif { "none", SSH_CIPHER_NONE, 8, 0, 0, 0, 0, CFLAG_NONE, NULL }, #endif /* WITH_OPENSSL */ { "chacha20-poly1305@openssh.com", @@ -293,6 +310,8 @@ cipher_init(struct sshcipher_ctx *cc, const struct sshcipher *cipher, const u_char *key, u_int keylen, const u_char *iv, u_int ivlen, int do_encrypt) { + + #ifdef WITH_OPENSSL int ret = SSH_ERR_INTERNAL_ERROR; const EVP_CIPHER *type; @@ -316,11 +335,25 @@ cipher_init(struct sshcipher_ctx *cc, const struct sshcipher *cipher, return chachapoly_init(&cc->cp_ctx, key, keylen); } #ifndef WITH_OPENSSL + +#ifdef USE_MSCNG + + /* cng shares cipher flag with NONE. Make sure the NONE cipher isn't requested */ + if ((cc->cipher->flags & CFLAG_NONE) == 0) + { + + if (cng_cipher_init(&cc->cng_ctx,key,keylen,iv, ivlen,cc->cipher->flags)) + return SSH_ERR_LIBCRYPTO_ERROR; + + return 0; + } +#else if ((cc->cipher->flags & CFLAG_AESCTR) != 0) { aesctr_keysetup(&cc->ac_ctx, key, 8 * keylen, 8 * ivlen); aesctr_ivsetup(&cc->ac_ctx, iv); return 0; } +#endif if ((cc->cipher->flags & CFLAG_NONE) != 0) return 0; return SSH_ERR_INVALID_ARGUMENT; @@ -373,6 +406,7 @@ cipher_init(struct sshcipher_ctx *cc, const struct sshcipher *cipher, return 0; } + /* * cipher_crypt() operates as following: * Copy 'aadlen' bytes (without en/decryption) from 'src' to 'dest'. @@ -387,18 +421,44 @@ int cipher_crypt(struct sshcipher_ctx *cc, u_int seqnr, u_char *dest, const u_char *src, u_int len, u_int aadlen, u_int authlen) { +#ifdef USE_MSCNG + int ret = 0; +#endif + if ((cc->cipher->flags & CFLAG_CHACHAPOLY) != 0) { return chachapoly_crypt(&cc->cp_ctx, seqnr, dest, src, len, aadlen, authlen, cc->encrypt); } #ifndef WITH_OPENSSL - if ((cc->cipher->flags & CFLAG_AESCTR) != 0) { + +#ifdef USE_MSCNG + + /* cng shares cipher flag with NONE. Make sure the NONE cipher isn't requested */ + if ((cc->cipher->flags & CFLAG_NONE) == 0) + { + if (aadlen) + memcpy(dest, src, aadlen); + if (cc->encrypt) + ret = cng_cipher_encrypt(&cc->cng_ctx,dest+aadlen, len, src+aadlen,len); + else + ret = cng_cipher_decrypt(&cc->cng_ctx,dest+aadlen, len, src+aadlen, len); + + if (ret != len){ + return SSH_ERR_LIBCRYPTO_ERROR; + } + return 0; + } +#else + if ((cc->cipher->flags & CFLAG_AESCTR) != 0) { if (aadlen) memcpy(dest, src, aadlen); aesctr_encrypt_bytes(&cc->ac_ctx, src + aadlen, dest + aadlen, len); return 0; } +#endif + + if ((cc->cipher->flags & CFLAG_NONE) != 0) { memcpy(dest, src, aadlen + len); return 0; @@ -472,6 +532,10 @@ cipher_cleanup(struct sshcipher_ctx *cc) else if (EVP_CIPHER_CTX_cleanup(&cc->evp) == 0) return SSH_ERR_LIBCRYPTO_ERROR; #endif +#ifdef USE_MSCNG + else + cng_cipher_cleanup(&cc->cng_ctx); +#endif return 0; } diff --git a/cipher.h b/cipher.h index 06d4be4..6b49b4d 100644 --- a/cipher.h +++ b/cipher.h @@ -41,7 +41,9 @@ #include #include "cipher-chachapoly.h" #include "cipher-aesctr.h" - +#ifdef USE_MSCNG +#include "contrib/win32/win32compat/cng_cipher.h" +#endif /* * Cipher types for SSH-1. New types can be added, but old types should not * be removed for compatibility. The maximum allowed value is 31. @@ -70,6 +72,10 @@ struct sshcipher_ctx { struct chachapoly_ctx cp_ctx; /* XXX union with evp? */ struct aesctr_ctx ac_ctx; /* XXX union with evp? */ const struct sshcipher *cipher; + #ifdef USE_MSCNG + struct ssh_cng_cipher_ctx cng_ctx; + #endif + }; u_int cipher_mask_ssh1(int); diff --git a/config.h b/config.h index 06ac8a3..6263001 100644 --- a/config.h +++ b/config.h @@ -83,7 +83,7 @@ /* #undef BSD_AUTH */ /* Define if you want to specify the path to your lastlog file */ -/* #undef CONF_LASTLOG_FILE */ +#define CONF_LASTLOG_FILE "/var/log/lastlog" /* Define if you want to specify the path to your utmp file */ #define CONF_UTMP_FILE "/var/run/utmp" @@ -1540,107 +1540,108 @@ /* type to use in place of socklen_t if not defined */ /* #undef socklen_t */ -#define WIN32_LEAN_AND_MEAN 1 -#define _CRT_SECURE_NO_DEPRECATE 1 -#define _CRT_NONSTDC_NO_DEPRECATE 1 -#define WIN32_FIXME 1 -#undef USE_NTCREATETOKEN - -/* Define if you must implement a startup_needs function for your platform */ -#define HAVE_STARTUP_NEEDS 1 - -/* Define if your platform uses Winsock instead of BSD sockets (yeah, there are a lot of platforms like this :) */ -#define HAVE_WINSOCK 1 - -#define snprintf _snprintf - -#define BROKEN_READV_COMPARISON - -/* Override detection of some headers and functions on MinGW */ -#undef BROKEN_SNPRINTF -#define GETPGRP_VOID 1 -#undef HAVE_CRYPT_H -#define HAVE_DAEMON 1 -#undef HAVE_ENDIAN_H -#undef HAVE_FCNTL_H -#define HAVE_FREEADDRINFO 1 -#define HAVE_GAI_STRERROR 1 -#define HAVE_GETADDRINFO 1 -#define HAVE_GETGROUPLIST 1 -#define HAVE_GETNAMEINFO 1 -#undef HAVE_ID_IN_UTMPX -#define HAVE_INET_ATON 1 -#define HAVE_INET_NTOA 1 -#define HAVE_INNETGR 1 -#undef HAVE_LIBCRYPT -#define HAVE_MKDTEMP 1 -#define HAVE_NANOSLEEP 1 -#undef HAVE_PATHS_H -#undef HAVE_POLL_H -#undef HAVE_PROC_PID -#undef HAVE_PTY_H -#define HAVE_NANOSLEEP 1 -#define HAVE_READPASSPHRASE 1 -#define HAVE_REALPATH 1 -#undef HAVE_SIG_ATOMIC_T -#define HAVE_SIZE_T 1 -#undef HAVE_STRERROR -#define HAVE_STRMODE 1 -#undef __USE_W32_SOCKETS - -#ifdef __MINGW32__ /* FIXME: Use autoconf to set this correctly */ -/* Define to 1 if you have the `strcasecmp' function. */ -#define HAVE_STRCASECMP 1 - -/* Define to 1 if you have the `strncasecmp' function. */ -#define HAVE_STRNCASECMP 1 -#endif - -#define HAVE_STRUCT_IN6_ADDR 1 -#define HAVE_STRUCT_SOCKADDR_IN6 1 -#define HAVE_STRUCT_TIMEVAL 1 -#undef HAVE_SYS_CDEFS_H -#undef HAVE_SYS_SYSMACROS_H -#undef HAVE_SYS_MMAN_H -#undef HAVE_SYS_UN_H - -#define HAVE_TCGETPGRP 1 - -#undef HAVE_TIME - -#define HAVE_TRUNCATE 1 - -#define HAVE_VIS_H 1 - -#define MISSING_FD_MASK 1 -#define MISSING_HOWMANY 1 -#define MISSING_NFDBITS 1 - -#undef SSH_PRIVSEP_USER - -#define HAVE_OPENPTY 1 - -/* Fixes for loginrec.c */ -#undef CONF_UTMP_FILE -#undef CONF_WTMPX_FILE -#undef CONF_WTMP_FILE -#undef CONF_UTMPX_FILE -#undef CONF_LASTLOG_FILE - -#define BROKEN_SYS_TERMIO_H - -#define strerror strerror_win32 - -#define strerror strerror_win32 - -// PRAGMA SYS PORT -#define WITH_OPENSSL 1 -#define HAVE_KRB5_GET_ERROR_MESSAGE 1 -#define HAVE_KRB5_FREE_ERROR_MESSAGE 1 -#define HAVE_DECL_NFDBITS 0 -#define HAVE_DECL_HOWMANY 0 - -#define WIN32_ZLIB_NO 1 - -//#define HAVE_ARC4RANDOM_UNIFORM 1 - +#define WIN32_LEAN_AND_MEAN 1 +#define _CRT_SECURE_NO_DEPRECATE 1 +#define _CRT_NONSTDC_NO_DEPRECATE 1 +#define WIN32_FIXME 1 +#undef USE_NTCREATETOKEN + +/* Define if you must implement a startup_needs function for your platform */ +#define HAVE_STARTUP_NEEDS 1 + +/* Define if your platform uses Winsock instead of BSD sockets (yeah, there are a lot of platforms like this :) */ +#define HAVE_WINSOCK 1 + +#define snprintf _snprintf + +#define BROKEN_READV_COMPARISON + +/* Override detection of some headers and functions on MinGW */ +#undef BROKEN_SNPRINTF +#define GETPGRP_VOID 1 +#undef HAVE_CRYPT_H +#define HAVE_DAEMON 1 +#undef HAVE_ENDIAN_H +#undef HAVE_FCNTL_H +#define HAVE_FREEADDRINFO 1 +#define HAVE_GAI_STRERROR 1 +#define HAVE_GETADDRINFO 1 +#define HAVE_GETGROUPLIST 1 +#define HAVE_GETNAMEINFO 1 +#undef HAVE_ID_IN_UTMPX +#define HAVE_INET_ATON 1 +#define HAVE_INET_NTOA 1 +#define HAVE_INNETGR 1 +#undef HAVE_LIBCRYPT +#define HAVE_MKDTEMP 1 +#define HAVE_NANOSLEEP 1 +#undef HAVE_PATHS_H +#undef HAVE_POLL_H +#undef HAVE_PROC_PID +#undef HAVE_PTY_H +#define HAVE_NANOSLEEP 1 +#define HAVE_READPASSPHRASE 1 +#define HAVE_REALPATH 1 +#undef HAVE_SIG_ATOMIC_T +#define HAVE_SIZE_T 1 +#undef HAVE_STRERROR +#define HAVE_STRMODE 1 +#undef __USE_W32_SOCKETS + +#ifdef __MINGW32__ /* FIXME: Use autoconf to set this correctly */ +/* Define to 1 if you have the `strcasecmp' function. */ +#define HAVE_STRCASECMP 1 + +/* Define to 1 if you have the `strncasecmp' function. */ +#define HAVE_STRNCASECMP 1 +#endif + +#define HAVE_STRUCT_IN6_ADDR 1 +#define HAVE_STRUCT_SOCKADDR_IN6 1 +#define HAVE_STRUCT_TIMEVAL 1 +#undef HAVE_SYS_CDEFS_H +#undef HAVE_SYS_SYSMACROS_H +#undef HAVE_SYS_MMAN_H +#undef HAVE_SYS_UN_H + +#define HAVE_TCGETPGRP 1 + +#undef HAVE_TIME + +#define HAVE_TRUNCATE 1 + +#define HAVE_VIS_H 1 + +#define MISSING_FD_MASK 1 +#define MISSING_HOWMANY 1 +#define MISSING_NFDBITS 1 + +#undef SSH_PRIVSEP_USER + +#define HAVE_OPENPTY 1 + +/* Fixes for loginrec.c */ +#undef CONF_UTMP_FILE +#undef CONF_WTMPX_FILE +#undef CONF_WTMP_FILE +#undef CONF_UTMPX_FILE +#undef CONF_LASTLOG_FILE + +#define BROKEN_SYS_TERMIO_H + +#define strerror strerror_win32 + +#define strerror strerror_win32 + +// PRAGMA SYS PORT +#define WITH_OPENSSL 1 +#define HAVE_KRB5_GET_ERROR_MESSAGE 1 +#define HAVE_KRB5_FREE_ERROR_MESSAGE 1 +#define HAVE_DECL_NFDBITS 0 +#define HAVE_DECL_HOWMANY 0 + +#define WIN32_ZLIB_NO 1 +#define USE_MSCNG 1 + +//#define HAVE_ARC4RANDOM_UNIFORM 1 + diff --git a/config.h.tail b/config.h.tail index 8b6d40c..5336f54 100644 --- a/config.h.tail +++ b/config.h.tail @@ -99,6 +99,7 @@ #define HAVE_DECL_HOWMANY 0 #define WIN32_ZLIB_NO 1 +#define USE_MSCNG 1 //#define HAVE_ARC4RANDOM_UNIFORM 1 diff --git a/contrib/win32/win32compat/Makefile.in b/contrib/win32/win32compat/Makefile.in index 027f868..2661cb2 100644 --- a/contrib/win32/win32compat/Makefile.in +++ b/contrib/win32/win32compat/Makefile.in @@ -8,25 +8,32 @@ top_srcdir=@top_srcdir@ VPATH=@srcdir@ CC=@CC@ LD=@LD@ -CFLAGS=@CFLAGS@ -CPPFLAGS=-I. -I../../.. -I$(srcdir) -I$(top_srcdir) -I$(srcdir)/includes @CPPFLAGS@ @DEFS@ -LIBS=@LIBS@ +BCRYPTFLAGS=-I/usr/include/w32api +CFLAGS=@CFLAGS@ +CPPFLAGS=-I. -I../../.. -I$(srcdir) -I$(top_srcdir) -I$(srcdir)/includes @CPPFLAGS@ @DEFS@ -DUSE_MSCNG +LIBS=@LIBS@ -lbcrypt AR=@AR@ RANLIB=@RANLIB@ INSTALL=@INSTALL@ -LDFLAGS=-L. @LDFLAGS@ +LDFLAGS=-L. @LDFLAGS@ -L/lib/win32api WIN32COMPATFILES = daemon.o gettimeofday.o homedirhelp.o pwd.o sfds.o \ socket.o startupneeds.o strcasecmp.o syslog.o lsalogon.o lsastring.o \ - stringhelp.o deskright.o win32auth.o kerberos.o + stringhelp.o deskright.o win32auth.o kerberos.o cng_cipher.o ansiprsr.o console.o tnnet.o WIN32COMPATLIB=@LIBWIN32COMPAT@ +CNGFILES=cng_cipher.o + + .c.o: $(CC) $(CFLAGS) $(CPPFLAGS) -c $< all: $(WIN32COMPATLIB) +$(CNGFILES): %.o: %.c + $(CC) $(CFLAGS) $(BCRYPTFLAGS) $(CPPFLAGS) -c $< + install: clean: diff --git a/contrib/win32/win32compat/ansiprsr.c b/contrib/win32/win32compat/ansiprsr.c new file mode 100644 index 0000000..c3d5631 --- /dev/null +++ b/contrib/win32/win32compat/ansiprsr.c @@ -0,0 +1,922 @@ +/* ansiprsr.c + * Author: Pragma Systems, Inc. + * Contribution by Pragma Systems, Inc. for Microsoft openssh win32 port + * Copyright (c) 2011, 2015 Pragma Systems, Inc. + * All rights reserved + * + * ANSI Parser to run on Win32 based operating systems. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice. + * 2. Binaries produced provide no direct or implied warranties or any + * guarantee of performance or suitability. + */ + +#include +#include +#include +#include + +#include +#include + +#include "ansiprsr.h" +#include "tncon.h" +#include "tnnet.h" + +#define TS_IS 0 +#define TS_SEND 1 + +// items used from other modules +int NetWriteString(char* pszString, size_t cbString); +TelParams Parameters; +extern int lftocrlf; + +extern int ScreenX; +extern int ScreenY; +extern int ScrollTop; +extern int ScrollBottom; +// end of imports from outside module + +bool gbVTAppMode = false; + +// private message for port printing to +unsigned char VT_ST[] = { 0x1b, '/', '\0' }; + +static int AutoWrap = 1; + +int marginTop, marginBottom; +BOOL bAtEOLN = FALSE; + +static int term_mode; + +// ParseANSI globals - these need to be here, because sometimes blocks are sent +// in mid ANSI sequence +int iParam[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +int iCurrentParam = 0; +int bDelimiter = 0; +int bMode = 0; +int fcompletion = 1; +int bExtMode = 0; +int bCS0 = 0; +int bCS1 = 0; +int bBkMode = 0; +int bCharMode = 0; + + +BOOL fShiftOut = FALSE; +BOOL InPrintMode = FALSE; +BOOL fPcMode = FALSE; + +char printErr[] = "Unable to Print: Printer not assigned. Press any key to continue..."; + +#define MODE_CURSORAPP 0x0001 +#define MODE_ANSIVT52 0x0002 +#define MODE_COL132 0x0004 +#define MODE_SMOOTHSCROLL 0x0008 +#define MODE_REVERSESCREEN 0x0010 +#define MODE_ORIGINREL 0x0020 +#define MODE_WRAPAROUND 0x0040 +#define MODE_AUTOREPEAT 0x0080 +#define MODE_APPMODE 0x0100 +#define MODE_LNM 0x0200 +#define MODE_IRM_INSERT 0x0400 + +int VTMode = 0; + +#define MODE_CURSORAPP 0x0001 +#define MODE_ANSIVT52 0x0002 +#define MODE_COL132 0x0004 +#define MODE_SMOOTHSCROLL 0x0008 +#define MODE_REVERSESCREEN 0x0010 +#define MODE_ORIGINREL 0x0020 +#define MODE_WRAPAROUND 0x0040 +#define MODE_AUTOREPEAT 0x0080 +#define MODE_APPMODE 0x0100 +#define MODE_LNM 0x0200 + +char *GetTerminalId() +{ + return "\033[?1;2c"; +} + +char * GetStatusReport() +{ + return "\033[2;5R"; +} + +void BufConvertToG2(char * pszBuffer, int length) +{ + int i; + + for (i=0;i= (ConWindowSizeY()-1)) + { + ConScrollDown(ScrollTop,ScrollBottom); + ConMoveCursorPosition(-ConGetCursorX(),0); + } + else + ConMoveCursorPosition(-ConGetCursorX(),1); + bAtEOLN = FALSE; +} + +unsigned char* ParseBuffer(unsigned char* pszBuffer, unsigned char* pszBufferEnd) +{ + int CurrentX; + int CurrentY; + int rc = 0, bufLen, cmpLen, i; + + + if (!fcompletion) + { + if (pszBuffer < pszBufferEnd -1) + { + unsigned char * pszCurrent = pszBuffer+1; + unsigned char * pszNewCurrent = pszCurrent; + + if (term_mode == TERM_ANSI) + { + pszNewCurrent = ParseANSI(pszCurrent, pszBufferEnd); + } + else if (term_mode == TERM_VT52) + { + pszNewCurrent = ParseVT52(pszCurrent, pszBufferEnd); + } + if ( pszCurrent == pszNewCurrent ) // didn't move inside Parsefunction + { + pszNewCurrent += ConWriteString( (char *)pszCurrent, 1); + return pszBuffer + 1; + } + if (pszNewCurrent > pszCurrent ) + pszBuffer = pszNewCurrent; + } + } + switch ((unsigned char) (*pszBuffer)) + { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 11: + pszBuffer++; + break; + + case 7: + Beep( 1000, 400); + pszBuffer++; + break; + + case 8: + pszBuffer++; + if (!bAtEOLN) + { + CurrentX = ConGetCursorX(); + if (CurrentX == 0) + { + ConMoveCursorPosition( ScreenX-1,-1); + ConWriteString(" ",1); + // ConMoveCursorPosition(-1,0); + } + else + { + ConClearNFromCursorLeft(1); + ConMoveCursorPosition( -1, 0 ); + } + } + bAtEOLN = FALSE; + + //ConWriteString( " ", 1 ); + //ConMoveCursorPosition( -1, 0 ); + break; + + case 9: + { + if (bAtEOLN) GoToNextLine(); + int i, MoveRight = 8 - (ConGetCursorX() % 8); + + for ( i = 0; i < MoveRight; i++ ) + ConWriteString( " ", 1 ); + pszBuffer++; + AutoWrap = 1; + bAtEOLN = FALSE; + } + break; + + case 10: + + + pszBuffer++; + CurrentY = ConGetCursorY(); + + + if (CurrentY >= marginBottom ) + { + if (VTMode & MODE_APPMODE) + ConScrollDown(marginTop,marginBottom); + else + printf("\n"); + ConMoveCursorPosition(-ConGetCursorX(),0); + } + else + { + ConMoveCursorPosition(0,1); + } + if ( Parameters.nReceiveCRLF == ENUM_LF ) + ConMoveCursorPosition(-ConGetCursorX(),0); + AutoWrap = 1; + bAtEOLN = FALSE; + break; + + case 12: + pszBuffer++; + ConSetCursorPosition(0, 0); + ConClearScreen(); + AutoWrap = 1; + bAtEOLN = FALSE; + break; + + case 13: + pszBuffer++; + ConMoveCursorPosition(-ConGetCursorX(),0); + AutoWrap = 1; + bAtEOLN = FALSE; + break; + + case 14: + pszBuffer++; + fShiftOut = TRUE; + break; + + case 15: + fShiftOut = FALSE; + pszBuffer++; + break; + + case 27: + if (pszBuffer < pszBufferEnd -1) + { + unsigned char * pszCurrent = pszBuffer+1; + unsigned char * pszNewCurrent = pszCurrent; + + if ( *pszCurrent == 27 ) + { + pszNewCurrent += ConWriteString( (char *)pszCurrent, 1); + return pszBuffer + 1; + } + else + { + if (term_mode == TERM_ANSI) + { + pszNewCurrent = ParseANSI(pszCurrent, pszBufferEnd); + } + else if (term_mode == TERM_VT52) + { + pszNewCurrent = ParseVT52(pszCurrent, pszBufferEnd); + } + } + if (pszNewCurrent > pszCurrent ) + pszBuffer = pszNewCurrent; + } + break; + + default: + { + if (bAtEOLN) GoToNextLine(); + + unsigned char* pszCurrent = pszBuffer; + CurrentX = ConGetCursorX(); + + while ((pszCurrent < pszBufferEnd) && (*pszCurrent != (unsigned char)27) + && (*pszCurrent > (unsigned char)15) && (*pszCurrent != (unsigned char)255) + && (CurrentX++ < ScreenX )) + // (*pszCurrent != (char)15) && (*pszCurrent != (char)14) && + // (*pszCurrent != (char)12) && (*pszCurrent != (char)13) && (*pszCurrent != (char)8) && + // (*pszCurrent != (char)9)) + pszCurrent++; + + if (fShiftOut) + memset( pszBuffer, '|', pszCurrent-pszBuffer ); + + pszBuffer += ConWriteString((char *)pszBuffer, (int)(pszCurrent - pszBuffer)); + + if ((CurrentX >= ScreenX) && AutoWrap && !(VTMode & MODE_CURSORAPP) ) + { + bAtEOLN = TRUE; + } + + break; + } + } + + return pszBuffer; +} + + +unsigned char * GetNextChar(unsigned char * pszBuffer, unsigned char *pszBufferEnd) +{ + if (++pszBuffer > pszBufferEnd) + return NULL; + else + return pszBuffer; +} + +void ConSetExtendedMode(int iFunction, BOOL bEnable) +{ + switch(iFunction) + { + case 1: + if (bEnable){ + VTMode |= MODE_CURSORAPP; + gbVTAppMode = true; + }else{ + VTMode &= ~MODE_CURSORAPP; + gbVTAppMode = false; + } + break; + case 2: + if (!bEnable) + VTMode |= MODE_ANSIVT52; + break; + case 3: + if (bEnable) + VTMode |= MODE_COL132; + else + VTMode &= ~MODE_COL132; + break; + case 4: + if (bEnable) + VTMode |= MODE_SMOOTHSCROLL; + else + VTMode &= ~MODE_SMOOTHSCROLL; + break; + case 5: + if (bEnable) + VTMode |= MODE_REVERSESCREEN; + else + VTMode &= ~MODE_REVERSESCREEN; + break; + case 6: + if (bEnable) + VTMode |= MODE_ORIGINREL; + else + VTMode &= ~MODE_ORIGINREL; + break; + case 7: + if (bEnable) + VTMode |= MODE_WRAPAROUND; + else + VTMode &= ~MODE_WRAPAROUND; + break; + case 8: + if (bEnable) + VTMode |= MODE_AUTOREPEAT; + else + VTMode &= ~MODE_AUTOREPEAT; + break; + case 20: // LNM Mode CSI 20h + if (bEnable){ + VTMode |= MODE_LNM; + Parameters.nReceiveCRLF = ENUM_LF; + lftocrlf = 1; + }else{ + VTMode &= ~MODE_LNM; + Parameters.nReceiveCRLF = ENUM_CRLF; + lftocrlf = 0; + } + break; + case 25: + ConDisplayCursor(bEnable); + break; + + } + + if ((iFunction == 2) && (bEnable)) + { + term_mode = TERM_VT52; + } +} + +#define MODE_EXT 0x00000001 +#define MODE_CS0 0x00000002 +#define MODE_CS1 0x00000004 +#define MODE_CS2 0x00000008 +#define MODE_CS3 0x00000010 +#define MODE_BRK 0x00000020 +#define MODE_CHAR 0x00000040 +#define MODE_K 0x00000080 + +#define DIGI_MASK (MODE_CS0 | MODE_CS1 | MODE_CS2 | MODE_CS3 | MODE_CHAR) + +unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEnd) +{ + unsigned char * pszCurrent = pszBuffer; + const int nParam = 10; // Maximum number of parameters + int rc = 0; + static int SavedX = 0; + static int SavedY = 0; + SCREEN_HANDLE hScreen = NULL; + char anyKey[2] = " "; + WORD BytesRead; + char pszServerPort[10]; + int indx; + char jobName[40]; + + fcompletion = 0; + do + { + switch ((unsigned char) *pszCurrent) + { + case ';': // delimiter + bDelimiter = TRUE; + break; +// Modifiers + case '?': // Extended Mode + bMode |= MODE_EXT; + break; + case '(': + bMode |= MODE_CS0; + break; + case ')': + bMode |= MODE_CS1; + break; + case '*': + bMode |= MODE_CS2; + break; + case '+': + bMode |= MODE_CS3; + break; + case '[': + bMode |= MODE_BRK; + break; + case '#': + bMode |= MODE_CHAR; + break; + +// Termination Options + case 0: + fcompletion = 1; + break; + + case '}': + fcompletion = 1; + break; + + case '<': // character set + fcompletion = 1; + break; + + case '\\': + fcompletion = 1; + break; + + case '~': + fcompletion = 1; + break; + case '^': // private message pszCurrent++; + while (_strnicmp((const char *)pszCurrent, (const char *)VT_ST, strlen((const char *)VT_ST) ) )// while not stop + { + if (_strnicmp((const char *)pszCurrent, (const char *)VT_ST, strlen((const char *)VT_ST) ) ) + pszCurrent++; + } + pszCurrent += strlen((const char *)VT_ST) - 1; + fcompletion = 1; + break; + + case 'A': // British Character Set or Cursor Up + if (bMode & MODE_CHAR) + { + // Britsh Character Set + } + else if (bMode & MODE_BRK) + { + // Cursor UP + if (iCurrentParam < 1) + iParam[0] = 1; + ConMoveCursorPosition(0, -iParam[0]); +// AutoWrap = 0; + } + fcompletion = 1; + break; + case 'B': // US ASCII or Cursor down + if (bMode & MODE_CHAR) + { + // US ASCII Character Set + } + else if (bMode & MODE_BRK) + { + // Cursor DOWN + if (iCurrentParam < 1) + iParam[0] = 1; + ConMoveCursorPosition(0, iParam[0]); +// AutoWrap = 0; + } + fcompletion = 1; + break; + case 'C': // Finish Character Set or Cursor right + if (bMode & MODE_CHAR) + { + // Britsh Character Set + } + else if (bMode & MODE_BRK) + { + // Cursor right + if (iCurrentParam < 1) + iParam[0] = 1; + ConMoveCursorPosition(iParam[0], 0); +// AutoWrap = 0; + } + fcompletion = 1; + break; + case 'D': // Cursor left + if (bMode & MODE_BRK) + { + // Cursor left + if (iCurrentParam < 1) + iParam[0] = 1; + ConMoveCursorPosition(-iParam[0], 0); +// AutoWrap = 0; + } + else if (bMode == 0) + { + // Index + ConScrollDown(ScrollTop,ScrollBottom); + } + fcompletion = 1; + bAtEOLN = FALSE; + break; + + + case '=': // application mode + VTMode |= MODE_APPMODE; + fcompletion = 1; + break; + case '>': // numeric mode + VTMode &= ~MODE_APPMODE; + fcompletion = 1; + break; + + case '%': // character set definitions + + fcompletion = 1; + break; + case 'h': + case 'l': // ^[?25h + if (bMode & MODE_EXT) + { + if (iParam[0] == 4){ + VTMode |= MODE_IRM_INSERT; + } +// iParam[0] = atoi( (pszCurrent - iCurrentParam) ); + int i; + for ( i = 0; i < iCurrentParam; i++ ) + ConSetExtendedMode(iParam[i], *pszCurrent=='h'?1:0); + } + else if (bMode & MODE_BRK) + { + // Possible set Line feed (option 20) + // Possible set Line feed (option 20) + if (iParam[0] == 20) + ConSetExtendedMode(iParam[0], *pszCurrent=='h'?1:0); + if (iParam[0] == 4){ + VTMode &= ~MODE_IRM_INSERT; + } + } + fcompletion = 1; + break; + + case 'L': + if (iParam[0]) + { + int i; + for (i=0; i 0) ? iParam[0] - 1 : 0; + marginBottom = (iParam[1] > 0) ? iParam[1] - 1 : 0; + + fcompletion = 1; + break; + case 'H': + case 'f': + if (bMode & MODE_BRK) + { + if ((iParam[0]-1) > ConWindowSizeY()) + ConSetScreenRect(ConWindowSizeX(), iParam[0]-1); + ConSetCursorPosition((iParam[1] > 0) ? iParam[1] - 1 : 0, (iParam[0] > 0) ? iParam[0] - 1 : 0); + //AutoWrap = 0; + } + else if (bMode == 0) + { + //Set tab + } + fcompletion = 1; + bAtEOLN = FALSE; + break; + + case 'M': + if (iParam[0]) + { + int i ; + for (i=0; i': // Exit Alt Keypad mode + case '1': // Graphics processor on + case '2': // Graphics processor off + pszCurrent++; + break; + case '<': // Enter ANSI mode + term_mode = TERM_ANSI; + pszCurrent++; + break; + default: + pszCurrent++; + } + + return pszCurrent; + +} diff --git a/contrib/win32/win32compat/ansiprsr.h b/contrib/win32/win32compat/ansiprsr.h new file mode 100644 index 0000000..96e1159 --- /dev/null +++ b/contrib/win32/win32compat/ansiprsr.h @@ -0,0 +1,46 @@ +/* ansiprsr.h + * Author: Pragma Systems, Inc. + * Contribution by Pragma Systems, Inc. for Microsoft openssh win32 port + * Copyright (c) 2011, 2015 Pragma Systems, Inc. + * All rights reserved + * + * ANSI Parser header file to run on Win32 based operating systems. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice. + * 2. Binaries produced provide no direct or implied warranties or any + * guarantee of performance or suitability. + */ + +#ifndef __ANSIPRSR_H +#define __ANSIPRSR_H + +#define TERM_ANSI 0 +#define TERM_VT52 1 + +unsigned char * ParseBuffer(unsigned char* pszBuffer, unsigned char* pszBufferEnd); +unsigned char * GetNextChar(unsigned char * pszBuffer, unsigned char *pszBufferEnd); +unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEnd); +unsigned char * ParseVT52(unsigned char * pszBuffer, unsigned char * pszBufferEnd); + +#define true TRUE +#define false FALSE +#define bool BOOL + +//typedef enum _crlftype { CRLF = 0, LF, CR } CRLFType; +#define ENUM_CRLF 0 +#define ENUM_LF 1 +#define ENUM_CR 2 + +typedef struct _TelParams +{ + int timeOut; + int fLocalEcho; + int fTreatLFasCRLF; + int fSendCROnly; + int nReceiveCRLF; +} TelParams; + +#endif \ No newline at end of file diff --git a/contrib/win32/win32compat/cng_cipher.c b/contrib/win32/win32compat/cng_cipher.c new file mode 100644 index 0000000..d95db8c --- /dev/null +++ b/contrib/win32/win32compat/cng_cipher.c @@ -0,0 +1,298 @@ +/* cng_cipher.c +* Author: Pragma Systems, Inc. +* Contribution by Pragma Systems, Inc. for Microsoft openssh win32 port +* Copyright (c) 2011, 2015 Pragma Systems, Inc. +* All rights reserved +* +* Common library for Windows Console Screen IO. +* Contains Windows console related definition so that emulation code can draw +* on Windows console screen surface. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice. +* 2. Binaries produced provide no direct or implied warranties or any +* guarantee of performance or suitability. +*/ + +#include +#include + +#include "cng_cipher.h" + +#ifdef USE_MSCNG + + +#define AES_BLOCK_SIZE 16 + + +/* +* increment the aes counter (iv) +*/ +static void aesctr_inc(unsigned char *ctr, unsigned int len) +{ + size_t i; + +#ifndef CONSTANT_TIME_INCREMENT + for (i = len - 1; i >= 0; i--) + if (++ctr[i]) /* continue on overflow */ + return; +#else + u8 x, add = 1; + + for (i = len - 1; i >= 0; i--) { + ctr[i] += add; + /* constant time for: x = ctr[i] ? 1 : 0 */ + x = ctr[i]; + x = (x | (x >> 4)) & 0xf; + x = (x | (x >> 2)) & 0x3; + x = (x | (x >> 1)) & 0x1; + add *= (x ^ 1); + } +#endif +} + + +/* +* Routine to encrypt a counter for ctr encryption. This requries +* us to use an IV that is reset for each call to avoid cng attempting +* to chain encryptions. +*/ +DWORD cng_counter_encrypt(const unsigned char *in, unsigned char *out, BCRYPT_KEY_HANDLE key, unsigned int blocklen) +{ + HRESULT status = S_OK; + DWORD cbResult = 0; + + unsigned char iv[AES_BLOCK_SIZE] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + + status = BCryptEncrypt( + key, + (PUCHAR)in, + blocklen, + NULL, + iv, + blocklen, + out, + blocklen, + &cbResult, + 0); + + return cbResult; +} + +/* +* Encrypt/Decrypt data using a CTR mode. +* In this mode, we can't call CNG encryption/decription directly. The mode requires +* the use of the iv as a counter that is incremented and encrypted. The +* encrypted counter is then XORd with the data to produce the cipher text. +*/ +int cng_aesctr_encrypt_bytes(PSSH_CNG_CIPHER_CTX x, const unsigned char *m, unsigned char *c, unsigned int bytes) +{ + int ret = 0; + unsigned int n = 0; + unsigned char buf[AES_BLOCK_SIZE]; + + while ((bytes--) > 0) { + if (n == 0) { + if (!cng_counter_encrypt(x->pbIV, buf, x->hKey, AES_BLOCK_SIZE)) + { + ret = -1; + break; + } + aesctr_inc(x->pbIV, AES_BLOCK_SIZE); + } + *(c++) = *(m++) ^ buf[n]; + n = (n + 1) % AES_BLOCK_SIZE; + } + return ret; +} + + +/* +* Encrypt data using a provided cipher context +*/ +unsigned int cng_cipher_encrypt(PSSH_CNG_CIPHER_CTX x, unsigned char *dest, unsigned int dest_len, const unsigned char *src, unsigned int len) +{ + DWORD cbResult = 0; + HRESULT status = S_OK; + + if (x->flags & _CNG_MODE_CTR) + { + if (-1 == cng_aesctr_encrypt_bytes(x, src, dest, len)) + { + status = GetLastError(); + } + cbResult = len; + } + else + { + + status = BCryptEncrypt( + x->hKey, + (PUCHAR)src, + len, + NULL, + x->pbIV, + x->cbBlockSize, + dest, + dest_len, + &cbResult, + 0); + if (S_OK != status) + { + cbResult = 0; + SetLastError(status); + } + } + return cbResult; +} + +/* +* Decrypt encrypted data using a provided cipher context +*/ +unsigned int cng_cipher_decrypt(PSSH_CNG_CIPHER_CTX x, unsigned char *dest, unsigned int dest_len, const unsigned char *src, unsigned int len) +{ + DWORD cbResult = 0; + HRESULT status = S_OK; + + if (x->flags & _CNG_MODE_CTR) + { + // ctr mode is just an XOR so encrypt=decrypt + if (-1 == cng_aesctr_encrypt_bytes(x, src, dest, len)) + { + status = GetLastError(); + } + cbResult = len; + } + else + { + + status = BCryptDecrypt( + x->hKey, + (PUCHAR)src, + len, + NULL, + x->pbIV, + x->cbBlockSize, + dest, + dest_len, + &cbResult, + 0); + if (S_OK != status) + { + cbResult = 0; + SetLastError(status); + } + } + return cbResult; +} + + +/* +* Initialize cipher context +*/ +unsigned int cng_cipher_init(PSSH_CNG_CIPHER_CTX x, const unsigned char *key, unsigned int keylen, const unsigned char *iv, size_t ivlen, unsigned int flags) +{ + HRESULT status = S_OK; + BCRYPT_ALG_HANDLE hAlg = NULL; + DWORD cbData = 0; + LPCWSTR pAlg = NULL; + DWORD cbBlockLen = 0; + + if ((0 == (flags & _CNG_CIPHER_AES)) || (0 == (flags & (_CNG_MODE_CBC | _CNG_MODE_CTR)))) + return STATUS_INVALID_PARAMETER; + + + + // wipe out old context + memset(x, 0, sizeof(SSH_CNG_CIPHER_CTX)); + + + // initialize simple context fields + x->flags = flags; + + // only one cipher supported right now + if (flags & _CNG_CIPHER_AES) + pAlg = BCRYPT_AES_ALGORITHM; + + + // Generate BCrypt Key and set mode if applicable + if (NT_SUCCESS(status = BCryptOpenAlgorithmProvider( + &hAlg, + pAlg, + NULL, + 0))) + { + + if (NT_SUCCESS(status = BCryptGetProperty( + hAlg, + BCRYPT_BLOCK_LENGTH, + (PBYTE)&cbBlockLen, + sizeof(DWORD), + &cbData, + 0))) + { + x->cbBlockSize = cbBlockLen; + if (cbBlockLen != ivlen) + { + status = STATUS_INVALID_PARAMETER; + } + else + { + x->pbIV = (PBYTE)HeapAlloc(GetProcessHeap(), 0, ivlen); + if (NULL == x->pbIV) + { + status = GetLastError(); + } + else + { + memcpy(x->pbIV, iv, ivlen); + } + } + } + + + if (status == S_OK && flags & _CNG_MODE_CBC) + { + status = BCryptSetProperty( + hAlg, + BCRYPT_CHAINING_MODE, + (PBYTE)BCRYPT_CHAIN_MODE_CBC, + sizeof(BCRYPT_CHAIN_MODE_CBC), + 0); + } + + if (status == S_OK) + { + status = BCryptGenerateSymmetricKey( + hAlg, + &(x->hKey), + NULL, + 0, + (PBYTE)key, + keylen, + 0); + } + BCryptCloseAlgorithmProvider(hAlg, 0); + + // if we got an error along the way, free up the iv + if (status != S_OK && x->pbIV) + { + HeapFree(GetProcessHeap(), 0, x->pbIV); + } + } + return status; +} +/* +* Cleanup cipher context fields +*/ +void cng_cipher_cleanup(PSSH_CNG_CIPHER_CTX x) +{ + if (x->pbIV) + HeapFree(GetProcessHeap(), 0, x->pbIV); + if (x->hKey) + BCryptDestroyKey(x->hKey); +} + +#endif \ No newline at end of file diff --git a/contrib/win32/win32compat/cng_cipher.h b/contrib/win32/win32compat/cng_cipher.h new file mode 100644 index 0000000..8b9ca9d --- /dev/null +++ b/contrib/win32/win32compat/cng_cipher.h @@ -0,0 +1,64 @@ +/* cng_cipher.h +* Author: Pragma Systems, Inc. +* Contribution by Pragma Systems, Inc. for Microsoft openssh win32 port +* Copyright (c) 2011, 2015 Pragma Systems, Inc. +* All rights reserved +* +* Common library for Windows Console Screen IO. +* Contains Windows console related definition so that emulation code can draw +* on Windows console screen surface. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice. +* 2. Binaries produced provide no direct or implied warranties or any +* guarantee of performance or suitability. +*/ + + +#ifndef CNG_CIPHER_H +#define CNG_CIPHER_H + +#ifdef USE_MSCNG + +#ifdef __cplusplus +extern "C" { +#endif + +#define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0) + +#define STATUS_UNSUCCESSFUL ((NTSTATUS)0xC0000001L) + +/* CIPHER/MODE bits specify cipher and mode in the flags +* field of the context +*/ +#define _CNG_CIPHER_AES 0x00000001 +#define _CNG_MODE_CTR 0x00010000 +#define _CNG_MODE_CBC 0x00020000 + +#define _CNG_CIPHER_MASK 0x0000FFFF +#define _CNG_MODE_MASK 0xFFFF0000 + + typedef struct ssh_cng_cipher_ctx + { + void * hKey; + unsigned char * pbIV; + unsigned int cbBlockSize; + unsigned int flags; + } SSH_CNG_CIPHER_CTX, *PSSH_CNG_CIPHER_CTX; + + + unsigned int cng_cipher_encrypt(PSSH_CNG_CIPHER_CTX x, unsigned char *dest, unsigned int dest_len, const unsigned char *src, unsigned int len); + unsigned int cng_cipher_decrypt(PSSH_CNG_CIPHER_CTX x, unsigned char *dest, unsigned int dest_len, const unsigned char *src, unsigned int len); + unsigned int cng_cipher_init(PSSH_CNG_CIPHER_CTX x, const unsigned char *key, unsigned int keylen, const unsigned char *iv, size_t ivlen, unsigned int flags); + void cng_cipher_cleanup(PSSH_CNG_CIPHER_CTX x); + + +#ifdef __cplusplus +} +#endif + +#endif + +#endif \ No newline at end of file diff --git a/contrib/win32/win32compat/console.c b/contrib/win32/win32compat/console.c new file mode 100644 index 0000000..4ed1b8b --- /dev/null +++ b/contrib/win32/win32compat/console.c @@ -0,0 +1,1764 @@ +/* console.c + * Author: Pragma Systems, Inc. + * Contribution by Pragma Systems, Inc. for Microsoft openssh win32 port + * Copyright (c) 2011, 2015 Pragma Systems, Inc. + * All rights reserved + * + * Common library for Windows Console Screen IO. + * Contains Windows console related definition so that emulation code can draw + * on Windows console screen surface. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice. + * 2. Binaries produced provide no direct or implied warranties or any + * guarantee of performance or suitability. + */ + +#include +#include +#include + +#include + +#include +#include + +HANDLE hConsole = NULL; +DWORD dwSavedAttributes = 0; + +WORD wStartingAttributes = 0; + +int ScreenX; +int ScreenY; +int ScrollTop; +int ScrollBottom; + +char *pSavedScreen = NULL; +static COORD ZeroCoord = {0,0}; +COORD SavedScreenSize = {0,0}; +COORD SavedScreenCursor = {0, 0 }; +SMALL_RECT SavedViewRect = {0,0,0,0}; + +typedef struct _SCREEN_RECORD{ + PCHAR_INFO pScreenBuf; + COORD ScreenSize; + COORD ScreenCursor; + SMALL_RECT srWindowRect; +}SCREEN_RECORD,*PSCREEN_RECORD; + +PSCREEN_RECORD pSavedScreenRec = NULL; + + +/* ************************************************************ */ +/* Function: ConInit */ +/* Used to Initialize the Console for output */ +/* ************************************************************ */ +int ConInit( DWORD OutputHandle, bool fSmartInit ) +{ + + OSVERSIONINFO os; + DWORD dwAttributes = 0; + CONSOLE_SCREEN_BUFFER_INFO csbi; + static bool bFirstConInit = true; + + os.dwOSVersionInfoSize = sizeof( OSVERSIONINFO ); + GetVersionEx( &os ); + + hConsole = GetStdHandle( OutputHandle ); + if (hConsole == INVALID_HANDLE_VALUE) + printf("GetStdHandle failed with %d\n",GetLastError()); + + if (!GetConsoleMode( hConsole, &dwSavedAttributes )) + printf("GetConsoleMode failed with %d\n",GetLastError()); + + dwAttributes = dwSavedAttributes; + + if ( os.dwPlatformId == VER_PLATFORM_WIN32_NT ) + { +// dwAttributes = (DWORD)ENABLE_WRAP_AT_EOL_OUTPUT; // Causes screen scroll in Edit +// dwAttributes = (DWORD)(ENABLE_PROCESSED_OUTPUT & ~(ENABLE_WRAP_AT_EOL_OUTPUT)); +// dwAttributes = 0; // Causes wrong FONTS and doesn't handle CRLF + dwAttributes = (DWORD)ENABLE_PROCESSED_OUTPUT; // PERFECT in NT +// dwAttributes = (DWORD)ENABLE_PROCESSED_OUTPUT | (DWORD)ENABLE_WRAP_AT_EOL_OUTPUT; // PERFECT in NT + SetConsoleMode(hConsole, dwAttributes ); // Windows NT + } + else + { + dwAttributes = (DWORD)ENABLE_WRAP_AT_EOL_OUTPUT; // Doesn't always print last column & doesn't handle CRLF +// dwAttributes = (DWORD)(ENABLE_PROCESSED_OUTPUT & ~(ENABLE_WRAP_AT_EOL_OUTPUT)); +// dwAttributes = 0; // Causes wrong FONTS and doesn't handle CRLF +// dwAttributes = (DWORD)ENABLE_PROCESSED_OUTPUT; // Scrolls in Windows 95 + SetConsoleMode(hConsole, dwAttributes ); // Windows 95 + } + + + + + if (bFirstConInit && fSmartInit) + { + + if (GetConsoleScreenBufferInfo(hConsole, &csbi)) + { + SMALL_RECT sr; + + wStartingAttributes = csbi.wAttributes; + + int ydelta = csbi.srWindow.Bottom-csbi.srWindow.Top+1; + if (csbi.dwCursorPosition.Y+ydelta > csbi.dwSize.Y) + { + // not enough buffer to reposition window.. must scroll + SMALL_RECT ScrollRect; + SMALL_RECT ClipRect; + COORD destination; + CHAR_INFO Fill; + COORD newCursorPos; + + ScrollRect.Top = (csbi.dwCursorPosition.Y+ydelta - csbi.dwSize.Y); + ScrollRect.Bottom = csbi.dwCursorPosition.Y+1; + ScrollRect.Left = 0; + ScrollRect.Right = csbi.dwSize.X; + + ClipRect = ScrollRect; + ClipRect.Top = 0; + + destination.X = 0; + destination.Y = 0; + + Fill.Attributes = csbi.wAttributes; + Fill.Char.AsciiChar = ' '; + + + ScrollConsoleScreenBuffer( hConsole, + &ScrollRect, + &ClipRect, + destination, + &Fill + ); + + + + + newCursorPos.Y = csbi.dwSize.Y-ydelta; + + + newCursorPos.X = csbi.dwCursorPosition.X; + SetConsoleCursorPosition(hConsole,newCursorPos); + + sr = csbi.srWindow; + sr.Top = newCursorPos.Y; + sr.Bottom = csbi.dwSize.Y-1; + + + BOOL rc = SetConsoleWindowInfo(hConsole,TRUE,&sr); + + + }else{ + GetConsoleScreenBufferInfo(hConsole, &csbi); + + sr = csbi.srWindow; + sr.Top = csbi.dwCursorPosition.Y; + sr.Bottom = sr.Top+ydelta-1; + + + BOOL rc = SetConsoleWindowInfo(hConsole,TRUE,&sr); + } + + } + bFirstConInit = false; + } + + ConSetScreenX(); + ConSetScreenY(); + ScrollTop = 0; + ScrollBottom = ConWindowSizeY(); + + if (GetConsoleScreenBufferInfo(hConsole, &csbi)) + SavedViewRect = csbi.srWindow; + + return 0; +} + + +/* ************************************************************ */ +/* Function: ConUnInit */ +/* Used to Uninitialize the Console */ +/* ************************************************************ */ +int ConUnInit( void ) +{ + CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + + if ( hConsole == NULL ) + return 0; + + + + if (!GetConsoleScreenBufferInfo(hConsole, &ConsoleInfo)) + return 0; + + SetConsoleMode(hConsole,dwSavedAttributes); + + + return 0; +} + +/* ************************************************************ */ +/* Function: ConUnInit */ +/* Used to Uninitialize the Console */ +/* ************************************************************ */ +int ConUnInitWithRestore( void ) +{ + DWORD dwWritten; + COORD Coord ; + CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + + if ( hConsole == NULL ) + return 0; + + + + if (!GetConsoleScreenBufferInfo(hConsole, &ConsoleInfo)) + return 0; + + SetConsoleMode(hConsole,dwSavedAttributes); + + Coord = ConsoleInfo.dwCursorPosition; + Coord.X = 0; + + DWORD dwNumChar = (ConsoleInfo.dwSize.Y - ConsoleInfo.dwCursorPosition.Y) * + ConsoleInfo.dwSize.X; + + FillConsoleOutputCharacter(hConsole, ' ', + dwNumChar, + Coord, &dwWritten); + FillConsoleOutputAttribute(hConsole, wStartingAttributes, + dwNumChar, + Coord, &dwWritten); + + SetConsoleTextAttribute( hConsole, wStartingAttributes ); + + return 0; +} + +// BLR - rewrite of ConSetScreenSize that doesn't alter buffer size + +BOOL ConSetScreenRect( int xSize, int ySize ) +{ + CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */ + BOOL bSuccess = TRUE; + SMALL_RECT srWindowRect; /* hold the new console size */ + COORD coordScreen; + + bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi); + + /* get the largest size we can size the console window to */ + coordScreen = GetLargestConsoleWindowSize(hConsole); + + /* define the new console window size and scroll position */ + srWindowRect.Top = csbi.srWindow.Top; + srWindowRect.Left = csbi.srWindow.Left; + srWindowRect.Right = xSize - 1 + srWindowRect.Left; + srWindowRect.Bottom = ySize - 1 + srWindowRect.Top; + + /* define the new console buffer size */ + coordScreen.X = max(csbi.dwSize.X, xSize); + coordScreen.Y = max(csbi.dwSize.Y, ySize); + + /* if the current buffer is larger than what we want, resize the */ + /* console window first, then the buffer */ + if (csbi.dwSize.X < coordScreen.X || + csbi.dwSize.Y < coordScreen.Y) + { + bSuccess = SetConsoleScreenBufferSize(hConsole, coordScreen); + if (bSuccess) + bSuccess = SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect); + } + else + { + bSuccess = SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect); + if (bSuccess) + bSuccess = SetConsoleScreenBufferSize(hConsole, coordScreen); + } + + if (bSuccess) + ConSaveViewRect(); + + /* if the current buffer *is* the size we want, don't do anything! */ + return bSuccess; +} + +BOOL ConSetScreenSize( int xSize, int ySize ) +{ + CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */ + BOOL bSuccess = TRUE; + SMALL_RECT srWindowRect; /* hold the new console size */ + COORD coordScreen; + + bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi); + + /* get the largest size we can size the console window to */ + coordScreen = GetLargestConsoleWindowSize(hConsole); + + /* define the new console window size and scroll position */ + srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1); + srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1); + srWindowRect.Left = srWindowRect.Top = (SHORT) 0; + + /* define the new console buffer size */ + coordScreen.X = xSize; + coordScreen.Y = ySize; + + /* if the current buffer is larger than what we want, resize the */ + /* console window first, then the buffer */ + if ((DWORD) csbi.dwSize.X * csbi.dwSize.Y > (DWORD) xSize * ySize) + { + bSuccess = SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect); + if (bSuccess) + { + bSuccess = SetConsoleScreenBufferSize(hConsole, coordScreen); + } + } + + /* if the current buffer is smaller than what we want, resize the */ + /* buffer first, then the console window */ + if ((DWORD) csbi.dwSize.X * csbi.dwSize.Y < (DWORD) xSize * ySize) + { + bSuccess = SetConsoleScreenBufferSize(hConsole, coordScreen); + if (bSuccess) + bSuccess = SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect); + } + + if (bSuccess) + ConSaveViewRect(); + + /* if the current buffer *is* the size we want, don't do anything! */ + return bSuccess; +} + +/* ************************************************************ */ +/* Function: ConRedrawScreen */ +/* Redraws the saved screen */ +/* ************************************************************ */ +DWORD ConRedrawScreen( void ) +{ + PCHAR_INFO pInfo; + CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + int i; + + if ( pSavedScreen == NULL ) + return 1; + + if (!GetConsoleScreenBufferInfo(hConsole, &ConsoleInfo)) + return 1; + + pInfo = (PCHAR_INFO)pSavedScreen; + + for ( i = 0; i < (ConsoleInfo.dwSize.X * ConsoleInfo.dwSize.Y); i++ ) + { + pInfo++; + } + return 0; +} + +bool fFirstTime = true; +/* ************************************************************ */ +/* Function: ConSetAttributes */ +/* Used to set the Color of the console and other attributes */ +/* 6/21/99 BLH commented out INTENSITY FLAGS for cyan, magenta, and yellow */ +/* it appears that they weren't commented out when the check for intensity + was added - since i'm not sure why we would explicitly state high + intensity for those colors +/* ************************************************************ */ +void ConSetAttribute( int *iParam, int iParamCount ) +{ + int iAttr; + int i; + + iAttr = 0; + if (iParamCount < 1) + SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); + else + { + for (i=0;i