I took a look at patch:

    http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=290450#5

It was an interesting exercise to examine how to apply the patch after
hunks that didn't match etc.

The code compiles but I have not tested the result live.

Perhaps these may help to evaluate the work submitted by Ralf Zerres
<[email protected]> in the future. I've included wdiff listing of Debian
specific changes (also included in *.patch) which may be easier to read.

diff --git a/debian/control b/debian/control
index 9fb0fc9..51aa3e0 100644
--- a/debian/control
+++ b/debian/control
@@ -3,7 +3,7 @@ Section: x11
Priority: optional
Maintainer: Ola Lundqvist <[email protected]>
Standards-Version: 3.8.4
Build-Depends: debhelper (>> 7.1), lynx, zlib1g-dev, libjpeg-dev, libxaw7-dev 
(>> 4.1.0), perl-modules, xfonts-base, xutils-dev, libx11-dev, libxau-dev, 
libxext-dev, libxi-dev, libxkbfile-dev, libxmu-dev, libxt-dev, 
[-x11proto-core-dev-]{+x11proto-core-dev, libvncserver-dev+}
Homepage: http://www.tightvnc.com

Package: tightvncserver
diff --git a/debian/patches/series b/debian/patches/series
index 947ad5c..28b9c95 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -2,3 +2,4 @@
20-vncviewer--vncviewer.man.patch
30-ftbfs-mips.patch
debian-changes-1.3.9-6.1
{+40-ultravnc-mslogin-support.patch+}
diff --git a/debian/rules b/debian/rules
index e6662d3..32b9e2a 100755
--- a/debian/rules
+++ b/debian/rules
@@ -42,7 +42,7 @@ build-arch-stamp:

        # Add here command to compile/build the package.
        # Build first things.
        $(MAKE) {+LDPOSTLIBS=-lvncclient+} World
        # Build Xvnc
        (cd Xvnc; $(MAKE) World)

>From 5dc475820f1ad37d09a4590aa2fd0d845d4caae5 Mon Sep 17 00:00:00 2001
From: Jari Aalto <[email protected]>
Date: Fri, 10 May 2013 17:53:35 +0300
Subject: [PATCH] UltraVNC ms-login support
Organization: Private
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit

Signed-off-by: Jari Aalto <[email protected]>
---
 debian/control                                   |    2 +-
 debian/patches/40-ultravnc-mslogin-support.patch |  331 ++++++++++++++++++++++
 debian/patches/series                            |    1 +
 debian/rules                                     |    2 +-
 4 files changed, 334 insertions(+), 2 deletions(-)
 create mode 100644 debian/patches/40-ultravnc-mslogin-support.patch

diff --git a/debian/control b/debian/control
index 9fb0fc9..51aa3e0 100644
--- a/debian/control
+++ b/debian/control
@@ -3,7 +3,7 @@ Section: x11
 Priority: optional
 Maintainer: Ola Lundqvist <[email protected]>
 Standards-Version: 3.8.4
-Build-Depends: debhelper (>> 7.1), lynx, zlib1g-dev, libjpeg-dev, libxaw7-dev (>> 4.1.0), perl-modules, xfonts-base, xutils-dev, libx11-dev, libxau-dev, libxext-dev, libxi-dev, libxkbfile-dev, libxmu-dev, libxt-dev, x11proto-core-dev
+Build-Depends: debhelper (>> 7.1), lynx, zlib1g-dev, libjpeg-dev, libxaw7-dev (>> 4.1.0), perl-modules, xfonts-base, xutils-dev, libx11-dev, libxau-dev, libxext-dev, libxi-dev, libxkbfile-dev, libxmu-dev, libxt-dev, x11proto-core-dev, libvncserver-dev
 Homepage: http://www.tightvnc.com
 
 Package: tightvncserver
diff --git a/debian/patches/40-ultravnc-mslogin-support.patch b/debian/patches/40-ultravnc-mslogin-support.patch
new file mode 100644
index 0000000..4ac7ef8
--- /dev/null
+++ b/debian/patches/40-ultravnc-mslogin-support.patch
@@ -0,0 +1,331 @@
+From: Ralf Zerres <[email protected]>
+Subject: Support UltraVNC ms-login
+Bug-Debian: http://bugs.debian.org/290450
+
+---
+ include/vncauth.h         |    5 +
+ libvncauth/vncauth.c      |   56 ++++++++++++++++++++
+ vncviewer/argsresources.c |    6 +-
+ vncviewer/rfbproto.c      |  124 +++++++++++++++++++++++++++++++++-------------
+ vncviewer/vncviewer.h     |    1 
+ 5 files changed, 156 insertions(+), 36 deletions(-)
+
+--- a/include/vncauth.h
++++ b/include/vncauth.h
+@@ -23,8 +23,13 @@
+ 
+ #define MAXPWLEN 8
+ #define CHALLENGESIZE 16
++#define CHALLENGESIZEMS 64
++
+ 
+ extern int vncEncryptAndStorePasswd(char *passwd, char *fname);
+ extern char *vncDecryptPasswdFromFile(char *fname);
+ extern void vncRandomBytes(unsigned char *bytes);
++extern void vncRandomBytesMs(unsigned char *bytes);
++extern void vncEncryptPasswdMs(unsigned char *encryptedPasswd, char *passwd);
++extern void vncEncryptPasswd(unsigned char *encryptedPasswd, char *passwd);
+ extern void vncEncryptBytes(unsigned char *bytes, char *passwd);
+--- a/libvncauth/vncauth.c
++++ b/libvncauth/vncauth.c
+@@ -245,3 +245,59 @@
+ 	des(bytes+i, bytes+i);
+     }
+ }
++
++
++void
++vncEncryptPasswdMs( unsigned char *encryptedPasswd, char *passwd )
++{
++	unsigned int i;
++
++	/* pad password with nulls */
++	for (i = 0; i < 32; i++) {
++		if (i < strlen(passwd)) {
++			encryptedPasswd[i] = passwd[i];
++		} else {        
++			encryptedPasswd[i] = 0;
++		}
++	}
++
++/* Do encryption in-place - this way we overwrite our copy of the plaintext
++			 *        password */
++	deskey(s_fixedkey, EN0);
++	des(encryptedPasswd, encryptedPasswd);
++}
++
++
++void
++vncEncryptPasswd( unsigned char *encryptedPasswd, char *passwd )
++{
++	unsigned int i;
++
++	/* pad password with nulls */
++	for (i = 0; i < MAXPWLEN; i++) {
++		if (i < strlen(passwd)) {
++			encryptedPasswd[i] = passwd[i];
++		} else {
++			encryptedPasswd[i] = 0;
++		}
++	}
++
++/* Do encryption in-place - this way we overwrite our copy of the plaintext
++			 *        password */
++	deskey(s_fixedkey, EN0);
++	des(encryptedPasswd, encryptedPasswd);
++}
++
++
++void
++vncRandomBytesMs(unsigned char *where) {
++	int i;
++	static unsigned int seed;
++	seed += (unsigned int) time(0) + getpid() + getpid() * 987654;
++
++	srand(seed);
++	for (i=0; i < CHALLENGESIZEMS; i++) {
++		where[i] = (unsigned char)(rand() & 255);    
++	}
++}
++
+--- a/vncviewer/argsresources.c
++++ b/vncviewer/argsresources.c
+@@ -151,6 +151,9 @@
+ 
+   {"passwordFile", "PasswordFile", XtRString, sizeof(String),
+    XtOffsetOf(AppData, passwordFile), XtRImmediate, (XtPointer) 0},
++  
++  {"userName", "UserName", XtRString, sizeof(String),
++   XtOffsetOf(AppData, userName), XtRImmediate, (XtPointer) 0},
+ 
+   {"passwordDialog", "PasswordDialog", XtRBool, sizeof(Bool),
+    XtOffsetOf(AppData, passwordDialog), XtRImmediate, (XtPointer) False},
+@@ -225,13 +228,13 @@
+    XtOffsetOf(AppData, autoPass), XtRImmediate, (XtPointer) False}
+ };
+ 
+-
+ /*
+  * The cmdLineOptions array specifies how certain app resource specs can be set
+  * with command-line options.
+  */
+ 
+ XrmOptionDescRec cmdLineOptions[] = {
++  {"-user",          "*userName",           XrmoptionSepArg, 0},
+   {"-shared",        "*shareDesktop",       XrmoptionNoArg,  "True"},
+   {"-noshared",      "*shareDesktop",       XrmoptionNoArg,  "False"},
+   {"-viewonly",      "*viewOnly",           XrmoptionNoArg,  "True"},
+@@ -314,6 +317,7 @@
+ 	  "        -fullscreen\n"
+ 	  "        -noraiseonbeep\n"
+ 	  "        -passwd <PASSWD-FILENAME> (standard VNC authentication)\n"
++	  "        -user <username for ultravnc mslogon>\n"
+ 	  "        -encodings <ENCODING-LIST> (e.g. \"tight copyrect\")\n"
+ 	  "        -bgr233\n"
+ 	  "        -owncmap\n"
+--- a/vncviewer/rfbproto.c
++++ b/vncviewer/rfbproto.c
+@@ -1,6 +1,4 @@
+-/*
+- *  Copyright (C) 2000-2006 Constantin Kaplinsky.  All Rights Reserved.
+- *  Copyright (C) 2000 Tridia Corporation.  All Rights Reserved.
++/*  Copyright (C) 2000 Tridia Corporation.  All Rights Reserved.
+  *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+  *
+  *  This is free software; you can redistribute it and/or modify
+@@ -31,6 +29,8 @@
+ #include <zlib.h>
+ #include <jpeglib.h>
+ 
++Bool m_ms_logon = False;
++
+ static void InitCapabilities(void);
+ static Bool SetupTunneling(void);
+ static int ReadSecurityType(void);
+@@ -73,6 +73,11 @@
+ char *desktopName;
+ rfbPixelFormat myFormat;
+ rfbServerInitMsg si;
++unsigned char m_encPasswd[8];
++unsigned char m_encPasswdMs[32];
++char m_clearPasswd[256]; 
++
++
+ char *serverCutText = NULL;
+ Bool newServerCutText = False;
+ 
+@@ -186,6 +191,7 @@
+  * ConnectToRFBServer.
+  */
+ 
++
+ Bool
+ ConnectToRFBServer(const char *hostname, int port)
+ {
+@@ -207,10 +213,6 @@
+ }
+ 
+ 
+-/*
+- * InitialiseRFBConnection.
+- */
+-
+ Bool
+ InitialiseRFBConnection(void)
+ {
+@@ -224,6 +226,15 @@
+ 
+   if (listenSpecified)
+     errorMessageOnReadFailure = False;
++  m_encPasswd[0] = '\0';
++  char passwd[256];
++  char domain[256];
++  char user[256];
++  memset(passwd, 0, sizeof(char)*256);
++  memset(domain, 0, sizeof(char)*256);
++  memset(user, 0, sizeof(char)*256);
++  char *temp;
++
+ 
+   if (!ReadFromRFBServer(pv, sz_rfbProtocolVersionMsg))
+     return False;
+@@ -244,6 +255,9 @@
+   } else if (server_major == 3 && server_minor == 7) {
+     /* the server supports protocol 3.7 */
+     protocolMinorVersion = 7;
++  } else if (server_minor == 4) {
++      m_ms_logon = True;
++      fprintf(stdout,"Ultr@vnc mslogon detected\n");
+   } else {
+     /* any other server version, request the standard 3.3 */
+     protocolMinorVersion = 3;
+@@ -535,40 +549,65 @@
+ {
+   CARD32 authScheme;
+   CARD8 challenge[CHALLENGESIZE];
++  CARD8 challengems[CHALLENGESIZEMS];
+   char *passwd;
+   char  buffer[64];
+   char* cstatus;
+   int   len;
++  m_encPasswd[0] = '\0';
++  char domain[256];
++  char user[256];
++  /*  memset(passwd, 0, sizeof(char)*256); */
++  memset(domain, 0, sizeof(char)*256);
++  memset(user, 0, sizeof(char)*256);
++  char *temp;
+ 
+   fprintf(stderr, "Performing standard VNC authentication\n");
+ 
+-  if (!ReadFromRFBServer((char *)challenge, CHALLENGESIZE))
+-    return False;
+-
+-  if (appData.passwordFile) {
+-    passwd = vncDecryptPasswdFromFile(appData.passwordFile);
+-    if (!passwd) {
+-      fprintf(stderr, "Cannot read valid password from file \"%s\"\n",
+-	      appData.passwordFile);
+-      return False;
++  if (m_ms_logon) {
++	if (!appData.userName) {
++	printf("Username: ");
++    	fgets(user,255,stdin);
++	} else { 
++	strncpy(user,appData.userName,sizeof(user));
++	}
++	temp=strchr(user,0x0A);
++	if (temp) *temp='\0';
++        strncpy(passwd,getpass("Password: "),sizeof(passwd));
++    	strncpy(domain,".",2);
+     }
+-  } else if (appData.autoPass) {
+-    passwd = buffer;
+-    cstatus = fgets(buffer, sizeof buffer, stdin);
+-    if (cstatus == NULL)
+-       buffer[0] = '\0';
+-    else
+-    {
+-       len = strlen(buffer);
+-       if (len > 0 && buffer[len - 1] == '\n')
+-	  buffer[len - 1] = '\0';
++    if (m_ms_logon) vncEncryptPasswdMs(m_encPasswdMs, passwd);
++    vncEncryptPasswd(m_encPasswd, passwd);
++    if (m_ms_logon) if(!ReadFromRFBServer((char *)challengems, CHALLENGESIZEMS)) return False;
++    if(!ReadFromRFBServer((char *)challenge, CHALLENGESIZE))
++    return False;
++
++ if (!m_ms_logon) {
++    if (appData.passwordFile) {
++	strncpy(passwd,vncDecryptPasswdFromFile(appData.passwordFile),
++		sizeof(passwd));
++	if (!passwd) {
++	    fprintf(stderr, "Cannot read valid password from file \"%s\"\n",
++		    appData.passwordFile);
++	    return False;
++	}
++    } else if (appData.autoPass) {
++	passwd = buffer;
++	cstatus = fgets(buffer, sizeof buffer, stdin);
++	if (cstatus == NULL)
++	    buffer[0] = '\0';
++	else
++	    {
++		len = strlen(buffer);
++		if (len > 0 && buffer[len - 1] == '\n')
++		    buffer[len - 1] = '\0';
++	    }
++    } else if (appData.passwordDialog) {
++	strncpy(passwd,DoPasswordDialog(),sizeof(passwd));
++    } else {
++	strncpy(passwd,getpass("Password: "),sizeof(passwd));
+     }
+-  } else if (appData.passwordDialog) {
+-    passwd = DoPasswordDialog();
+-  } else {
+-    passwd = getpass("Password: ");
+-  }
+-
++    
+   if (!passwd || strlen(passwd) == 0) {
+     fprintf(stderr, "Reading password failed\n");
+     return False;
+@@ -576,10 +615,25 @@
+   if (strlen(passwd) > 8) {
+     passwd[8] = '\0';
+   }
++ }
++ 
++  if (m_ms_logon) {
++		int i=0;
++		for (i=0;i<32;i++)
++		{
++			challengems[i]=m_encPasswdMs[i]^challengems[i];
++		}
++		if(!WriteToRFBServer((char *) user, sizeof(char)*256)) return False;
++		if(!WriteToRFBServer((char *) domain, sizeof(char)*256)) return False;
++		if(!WriteToRFBServer((char *) challengems, CHALLENGESIZEMS)) return False;
++		vncEncryptBytes(challenge, passwd);
++		if(!WriteToRFBServer((char *) challenge, CHALLENGESIZE)) return False;
++  } else {
++		vncEncryptBytes(challenge, passwd);
++		if(!WriteToRFBServer((char *) challenge, CHALLENGESIZE)) return False;
++	}
+ 
+-  vncEncryptBytes(challenge, passwd);
+-
+-  /* Lose the password from memory */
++    /* Lose the password from memory  */
+   memset(passwd, '\0', strlen(passwd));
+ 
+   if (!WriteExact(rfbsock, (char *)challenge, CHALLENGESIZE))
+--- a/vncviewer/vncviewer.h
++++ b/vncviewer/vncviewer.h
+@@ -90,6 +90,7 @@
+   char *userLogin;
+ 
+   char *passwordFile;
++  char *userName;
+   Bool passwordDialog;
+ 
+   int rawDelay;
diff --git a/debian/patches/series b/debian/patches/series
index 947ad5c..28b9c95 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -2,3 +2,4 @@
 20-vncviewer--vncviewer.man.patch
 30-ftbfs-mips.patch
 debian-changes-1.3.9-6.1
+40-ultravnc-mslogin-support.patch
diff --git a/debian/rules b/debian/rules
index e6662d3..32b9e2a 100755
--- a/debian/rules
+++ b/debian/rules
@@ -42,7 +42,7 @@ build-arch-stamp:
 
 	# Add here command to compile/build the package.
 	# Build first things.
-	$(MAKE) World
+	$(MAKE) LDPOSTLIBS=-lvncclient World
 	# Build Xvnc
 	(cd Xvnc; $(MAKE) World)
 
-- 
1.7.10.4

Reply via email to