-PasswordFile support for Windows viewer as well


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@80 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/vncviewer/CViewOptions.cxx b/vncviewer/CViewOptions.cxx
index 1f55129..13ad7cd 100644
--- a/vncviewer/CViewOptions.cxx
+++ b/vncviewer/CViewOptions.cxx
@@ -30,6 +30,8 @@
 using namespace rfb;
 using namespace rfb::win32;
 
+static StringParameter passwordFile("PasswordFile",
+				    "Password file for VNC authentication", "");
 
 static BoolParameter useLocalCursor("UseLocalCursor", "Render the mouse cursor locally", true);
 static BoolParameter useDesktopResize("UseDesktopResize", "Support dynamic desktop resizing", true);
@@ -113,7 +115,7 @@
 protocol3_3(::protocol3_3), acceptBell(::acceptBell), lowColourLevel(::lowColourLevel),
 pointerEventInterval(ptrEventInterval), emulate3(::emulate3), monitor(::monitor.getData()),
 customCompressLevel(::customCompressLevel), compressLevel(::compressLevel), 
-noJpeg(::noJpeg), qualityLevel(::qualityLevel)
+noJpeg(::noJpeg), qualityLevel(::qualityLevel), passwordFile(::passwordFile.getData())
 {
   CharArray encodingName(::preferredEncoding.getData());
   preferredEncoding = encodingNum(encodingName.buf);
diff --git a/vncviewer/CViewOptions.h b/vncviewer/CViewOptions.h
index e45612c..d49cab1 100644
--- a/vncviewer/CViewOptions.h
+++ b/vncviewer/CViewOptions.h
@@ -83,6 +83,7 @@
       bool noJpeg;
       int qualityLevel;
 
+      CharArray passwordFile;
     };
 
 
diff --git a/vncviewer/cview.cxx b/vncviewer/cview.cxx
index 5d1ee5d..78fc4be 100644
--- a/vncviewer/cview.cxx
+++ b/vncviewer/cview.cxx
@@ -1484,6 +1484,19 @@
 }
 
 bool CView::getUserPasswd(char** user, char** password) {
+  if (!user && options.passwordFile.buf[0]) {
+    FILE* fp = fopen(options.passwordFile.buf, "r");
+    if (!fp) return false;
+    char data[256];
+    int datalen = fread(data, 1, 256, fp);
+    fclose(fp);
+    if (datalen != 8) return false;
+    vncAuthUnobfuscatePasswd(data);
+    *password = strDup(data);
+    memset(data, 0, strlen(data));
+    return true;
+  }
+
   if (user && options.userName.buf)
     *user = strDup(options.userName.buf);
   if (password && options.password.buf)