[Development] Move all VncAuth code from SSecurityFactoryStandard class to
SSecurityVncAuth class.


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4036 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/common/rfb/SSecurityFactoryStandard.cxx b/common/rfb/SSecurityFactoryStandard.cxx
index 6056a19..333d50b 100644
--- a/common/rfb/SSecurityFactoryStandard.cxx
+++ b/common/rfb/SSecurityFactoryStandard.cxx
@@ -42,18 +42,11 @@
  "None");
 
 
-StringParameter SSecurityFactoryStandard::vncAuthPasswdFile
-("PasswordFile", "Password file for VNC authentication", "");
-VncAuthPasswdParameter SSecurityFactoryStandard::vncAuthPasswd
-("Password", "Obfuscated binary encoding of the password which clients must supply to "
- "access the server", &SSecurityFactoryStandard::vncAuthPasswdFile);
-
-
 SSecurity* SSecurityFactoryStandard::getSSecurity(rdr::U8 secType, bool reverseConnection) {
   switch (secType) {
   case secTypeNone: return new SSecurityNone();
   case secTypeVncAuth:
-    return new SSecurityVncAuth(&vncAuthPasswd);
+    return new SSecurityVncAuth();
   default:
     throw Exception("Security type not supported");
   }
@@ -83,46 +76,3 @@
   }
 }
 
-
-VncAuthPasswdParameter::VncAuthPasswdParameter(const char* name,
-                                               const char* desc,
-                                               StringParameter* passwdFile_)
-: BinaryParameter(name, desc, 0, 0), passwdFile(passwdFile_) {
-}
-
-char* VncAuthPasswdParameter::getVncAuthPasswd() {
-  ObfuscatedPasswd obfuscated;
-  getData((void**)&obfuscated.buf, &obfuscated.length);
-
-  if (obfuscated.length == 0) {
-    if (passwdFile) {
-      CharArray fname(passwdFile->getData());
-      if (!fname.buf[0]) {
-        vlog.info("neither %s nor %s params set", getName(), passwdFile->getName());
-        return 0;
-      }
-
-      FILE* fp = fopen(fname.buf, "r");
-      if (!fp) {
-        vlog.error("opening password file '%s' failed",fname.buf);
-        return 0;
-      }
-
-      vlog.debug("reading password file");
-      obfuscated.buf = new char[128];
-      obfuscated.length = fread(obfuscated.buf, 1, 128, fp);
-      fclose(fp);
-    } else {
-      vlog.info("%s parameter not set", getName());
-    }
-  }
-
-  try {
-    PlainPasswd password(obfuscated);
-    return password.takeBuf();
-  } catch (...) {
-    return 0;
-  }
-}
-
-
diff --git a/common/rfb/SSecurityFactoryStandard.h b/common/rfb/SSecurityFactoryStandard.h
index 165881e..f55894e 100644
--- a/common/rfb/SSecurityFactoryStandard.h
+++ b/common/rfb/SSecurityFactoryStandard.h
@@ -44,22 +44,12 @@
 
 namespace rfb {
 
-  class VncAuthPasswdParameter : public VncAuthPasswdGetter, BinaryParameter {
-  public:
-    VncAuthPasswdParameter(const char* name, const char* desc, StringParameter* passwdFile_);
-    virtual char* getVncAuthPasswd();
-  protected:
-    StringParameter* passwdFile;
-  };
-
   class SSecurityFactoryStandard : public SSecurityFactory {
   public:
     virtual SSecurity* getSSecurity(rdr::U8 secType, bool reverse);
     virtual void getSecTypes(std::list<rdr::U8>* secTypes, bool reverse);
     static StringParameter sec_types;
     static StringParameter rev_sec_types;
-    static StringParameter vncAuthPasswdFile;
-    static VncAuthPasswdParameter vncAuthPasswd;
   protected:
     virtual bool isSecTypeSupported(rdr::U8 secType);
   };
diff --git a/common/rfb/SSecurityVncAuth.cxx b/common/rfb/SSecurityVncAuth.cxx
index 29a3b96..ca81bf3 100644
--- a/common/rfb/SSecurityVncAuth.cxx
+++ b/common/rfb/SSecurityVncAuth.cxx
@@ -40,9 +40,16 @@
 
 static LogWriter vlog("SVncAuth");
 
+StringParameter SSecurityVncAuth::vncAuthPasswdFile
+("PasswordFile", "Password file for VNC authentication", "", ConfServer);
+AliasParameter rfbauth("rfbauth", "Alias for PasswordFile",
+		       &SSecurityVncAuth::vncAuthPasswdFile, ConfServer);
+VncAuthPasswdParameter SSecurityVncAuth::vncAuthPasswd
+("Password", "Obfuscated binary encoding of the password which clients must supply to "
+ "access the server", &SSecurityVncAuth::vncAuthPasswdFile);
 
-SSecurityVncAuth::SSecurityVncAuth(VncAuthPasswdGetter* pg_)
-  : sentChallenge(false), responsePos(0), pg(pg_)
+SSecurityVncAuth::SSecurityVncAuth(void)
+  : sentChallenge(false), responsePos(0), pg(&vncAuthPasswd)
 {
 }
 
@@ -85,3 +92,45 @@
 
   return true;
 }
+
+VncAuthPasswdParameter::VncAuthPasswdParameter(const char* name,
+                                               const char* desc,
+                                               StringParameter* passwdFile_)
+: BinaryParameter(name, desc, 0, 0, ConfServer), passwdFile(passwdFile_) {
+}
+
+char* VncAuthPasswdParameter::getVncAuthPasswd() {
+  ObfuscatedPasswd obfuscated;
+  getData((void**)&obfuscated.buf, &obfuscated.length);
+
+  if (obfuscated.length == 0) {
+    if (passwdFile) {
+      CharArray fname(passwdFile->getData());
+      if (!fname.buf[0]) {
+        vlog.info("neither %s nor %s params set", getName(), passwdFile->getName());
+        return 0;
+      }
+
+      FILE* fp = fopen(fname.buf, "r");
+      if (!fp) {
+        vlog.error("opening password file '%s' failed",fname.buf);
+        return 0;
+      }
+
+      vlog.debug("reading password file");
+      obfuscated.buf = new char[128];
+      obfuscated.length = fread(obfuscated.buf, 1, 128, fp);
+      fclose(fp);
+    } else {
+      vlog.info("%s parameter not set", getName());
+    }
+  }
+
+  try {
+    PlainPasswd password(obfuscated);
+    return password.takeBuf();
+  } catch (...) {
+    return 0;
+  }
+}
+
diff --git a/common/rfb/SSecurityVncAuth.h b/common/rfb/SSecurityVncAuth.h
index 1f7e6ec..8a2d0f6 100644
--- a/common/rfb/SSecurityVncAuth.h
+++ b/common/rfb/SSecurityVncAuth.h
@@ -24,6 +24,7 @@
 #ifndef __RFB_SSECURITYVNCAUTH_H__
 #define __RFB_SSECURITYVNCAUTH_H__
 
+#include <rfb/Configuration.h>
 #include <rfb/SSecurity.h>
 #include <rfb/Security.h>
 #include <rdr/types.h>
@@ -37,12 +38,22 @@
     virtual char* getVncAuthPasswd()=0;
   };
 
+  class VncAuthPasswdParameter : public VncAuthPasswdGetter, BinaryParameter {
+  public:
+    VncAuthPasswdParameter(const char* name, const char* desc, StringParameter* passwdFile_);
+    virtual char* getVncAuthPasswd();
+  protected:
+    StringParameter* passwdFile;
+  };
+
   class SSecurityVncAuth : public SSecurity {
   public:
-    SSecurityVncAuth(VncAuthPasswdGetter* pg);
+    SSecurityVncAuth(void);
     virtual bool processMsg(SConnection* sc);
     virtual int getType() const {return secTypeVncAuth;}
     virtual const char* getUserName() const {return 0;}
+    static StringParameter vncAuthPasswdFile;
+    static VncAuthPasswdParameter vncAuthPasswd;
   private:
     enum {vncAuthChallengeSize = 16};
     rdr::U8 challenge[vncAuthChallengeSize];