Revision: 4252
          http://tigervnc.svn.sourceforge.net/tigervnc/?rev=4252&view=rev
Author:   atkac
Date:     2011-02-07 10:45:15 +0000 (Mon, 07 Feb 2011)

Log Message:
-----------
[Development] Rename function "gethomedir" to "getvnchomedir" and rewrite it in
platform-intependent manner.

Thanks to Guillaume Destuynder.

Modified Paths:
--------------
    trunk/common/os/os.cxx
    trunk/common/os/os.h
    trunk/common/rfb/CSecurityTLS.cxx
    trunk/unix/vncpasswd/vncpasswd.cxx
    trunk/unix/vncviewer/vncviewer.cxx

Modified: trunk/common/os/os.cxx
===================================================================
--- trunk/common/os/os.cxx      2011-02-07 09:37:21 UTC (rev 4251)
+++ trunk/common/os/os.cxx      2011-02-07 10:45:15 UTC (rev 4252)
@@ -36,7 +36,7 @@
 #include <shlobj.h>
 #endif
 
-int gethomedir(char **dirp)
+int getvnchomedir(char **dirp)
 {
 #ifndef WIN32
        char *homedir, *dir;
@@ -62,12 +62,13 @@
                homedir = passwd->pw_dir;
        }
 
-       len = strlen(homedir) + 1;
-       dir = new char[len];
+       len = strlen(homedir);
+       dir = new char[len+7];
        if (dir == NULL)
                return -1;
 
        memcpy(dir, homedir, len);
+       memcpy(dir + len, "/.vnc/\0", 7);
 #else
        dir = new TCHAR[MAX_PATH];
        if (dir == NULL)
@@ -78,10 +79,8 @@
                delete [] dir;
                return -1;
        }
-
-       
+       memcpy(dir+strlen(dir), (TCHAR *)"\\vnc\\\0", 6);
 #endif
-
        *dirp = dir;
        return 0;
 }

Modified: trunk/common/os/os.h
===================================================================
--- trunk/common/os/os.h        2011-02-07 09:37:21 UTC (rev 4251)
+++ trunk/common/os/os.h        2011-02-07 10:45:15 UTC (rev 4252)
@@ -24,7 +24,8 @@
 #endif
 
 /*
- * Get home directory. If HOME environment variable is set then it is returned.
+ * Get VNC home directory ($HOME/.vnc or %APPDATA%/vnc/).
+ * If HOME environment variable is set then it is used.
  * Otherwise home directory is obtained via getpwuid function.
  *
  * Note for Windows:
@@ -34,6 +35,6 @@
  * 0 - Success
  * -1 - Failure
  */
-int gethomedir(char **dirp);
+int getvnchomedir(char **dirp);
 
 #endif /* OS_OS_H */

Modified: trunk/common/rfb/CSecurityTLS.cxx
===================================================================
--- trunk/common/rfb/CSecurityTLS.cxx   2011-02-07 09:37:21 UTC (rev 4251)
+++ trunk/common/rfb/CSecurityTLS.cxx   2011-02-07 10:45:15 UTC (rev 4252)
@@ -89,25 +89,20 @@
 {
   char* homeDir = NULL;
 
-  if (gethomedir(&homeDir) == -1) {
-    vlog.error("Could not obtain home directory path");
+  if (getvnchomedir(&homeDir) == -1) {
+    vlog.error("Could not obtain VNC home directory path");
     return;
   }
 
-  CharArray caDefault(strlen(homeDir)+17);
-  sprintf(caDefault.buf, "%s/.vnc/x509_certs", homeDir);
+  int len = strlen(homeDir) + 1;
+  CharArray caDefault(len + 7);
+  CharArray crlDefault(len + 8);
+  sprintf(caDefault.buf, "%sx509_ca", homeDir);
+  sprintf(crlDefault.buf, "%s509_crl", homeDir);
   delete [] homeDir;
 
-#ifndef WIN32
-  /* XXX Do we need access() check here? */
-  if (!access(caDefault.buf, R_OK))
-    x509ca.setDefaultStr(strdup(caDefault.buf));
-  else
-    vlog.error("Failed to open ~/.vnc/x509_certs");
-#else
-  /* Windows doesn't have access() function. */
   x509ca.setDefaultStr(strdup(caDefault.buf));
-#endif
+  x509crl.setDefaultStr(strdup(crlDefault.buf));
 }
 
 void CSecurityTLS::shutdown()
@@ -349,13 +344,13 @@
          < 0)
         AuthFailureException("certificate issuer unknown, and certificate "
                             "export failed");
-      
-      if (gethomedir(&homeDir) == -1)
-        vlog.error("Could not obtain home directory path");
+
+      if (getvnchomedir(&homeDir) == -1)
+        vlog.error("Could not obtain VNC home directory path");
       else {
        FILE *f;
-        CharArray caSave(strlen(homeDir)+17);
-       sprintf(caSave.buf, "%s/.vnc/x509_certs", homeDir);
+       CharArray caSave(strlen(homeDir) + 11);
+       sprintf(caSave.buf, "%sx509_certs", homeDir);
        delete [] homeDir;
                f = fopen(caSave.buf, "a+");
        if (!f)

Modified: trunk/unix/vncpasswd/vncpasswd.cxx
===================================================================
--- trunk/unix/vncpasswd/vncpasswd.cxx  2011-02-07 09:37:21 UTC (rev 4251)
+++ trunk/unix/vncpasswd/vncpasswd.cxx  2011-02-07 10:45:15 UTC (rev 4252)
@@ -102,14 +102,13 @@
 
   if (!fname) {
     char *homeDir = NULL;
-    if (gethomedir(&homeDir) == -1) {
-      fprintf(stderr, "Can't obtain home directory\n");
+    if (getvnchomedir(&homeDir) == -1) {
+      fprintf(stderr, "Can't obtain VNC home directory\n");
       exit(1);
     }
-    fname = new char[strlen(homeDir) + 20];
-    sprintf(fname, "%s/.vnc", homeDir);
-    mkdir(fname, 0777);
-    sprintf(fname, "%s/.vnc/passwd", homeDir);
+    mkdir(homeDir, 0777);
+    fname = new char[strlen(homeDir) + 7];
+    sprintf(fname, "%spasswd", homeDir);
     delete [] homeDir;
   }
 

Modified: trunk/unix/vncviewer/vncviewer.cxx
===================================================================
--- trunk/unix/vncviewer/vncviewer.cxx  2011-02-07 09:37:21 UTC (rev 4251)
+++ trunk/unix/vncviewer/vncviewer.cxx  2011-02-07 10:45:15 UTC (rev 4252)
@@ -328,14 +328,13 @@
 
   // Create .vnc in the user's home directory if it doesn't already exist
   char* homeDir = NULL;
-  if (gethomedir(&homeDir) == -1)
-    vlog.error("Could not create .vnc directory: can't obtain home directory 
path.");
-  else {
-    CharArray vncDir(strlen(homeDir)+6);
-    sprintf(vncDir.buf, "%s/.vnc", homeDir);
-    int result =  mkdir(vncDir.buf, 0755);
+  if (getvnchomedir(&homeDir) == -1) {
+    vlog.error("Could not create VNC home directory: can't obtain home "
+              "directory path.");
+  } else {
+    int result =  mkdir(homeDir, 0755);
     if (result == -1 && errno != EEXIST)
-      vlog.error("Could not create .vnc directory: %s.", strerror(errno));
+      vlog.error("Could not create VNC home directory: %s.", strerror(errno));
     delete [] homeDir;
   }
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
The modern datacenter depends on network connectivity to access resources
and provide services. The best practices for maximizing a physical server's
connectivity to a physical network are well understood - see how these
rules translate into the virtual world? 
http://p.sf.net/sfu/oracle-sfdevnlfb
_______________________________________________
Tigervnc-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tigervnc-commits

Reply via email to