From: Adam Tkac Date: Mon, 7 Feb 2011 10:45:15 +0000 (+0000) Subject: [Development] Rename function "gethomedir" to "getvnchomedir" and rewrite it in X-Git-Tag: v1.0.90~67 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=af0817220ee171837b4c15019fe16c2d5de180ad;p=tigervnc.git [Development] Rename function "gethomedir" to "getvnchomedir" and rewrite it in platform-intependent manner. Thanks to Guillaume Destuynder. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4252 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- diff --git a/common/os/os.cxx b/common/os/os.cxx index fb07dcf6..c08b5728 100644 --- a/common/os/os.cxx +++ b/common/os/os.cxx @@ -36,7 +36,7 @@ #include #endif -int gethomedir(char **dirp) +int getvnchomedir(char **dirp) { #ifndef WIN32 char *homedir, *dir; @@ -62,12 +62,13 @@ int gethomedir(char **dirp) 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 @@ int gethomedir(char **dirp) delete [] dir; return -1; } - - + memcpy(dir+strlen(dir), (TCHAR *)"\\vnc\\\0", 6); #endif - *dirp = dir; return 0; } diff --git a/common/os/os.h b/common/os/os.h index 18e61e23..d011764e 100644 --- a/common/os/os.h +++ b/common/os/os.h @@ -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 */ diff --git a/common/rfb/CSecurityTLS.cxx b/common/rfb/CSecurityTLS.cxx index 88408686..427d2005 100644 --- a/common/rfb/CSecurityTLS.cxx +++ b/common/rfb/CSecurityTLS.cxx @@ -89,25 +89,20 @@ void CSecurityTLS::setDefaults() { 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 @@ void CSecurityTLS::checkSession() < 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) diff --git a/unix/vncpasswd/vncpasswd.cxx b/unix/vncpasswd/vncpasswd.cxx index 4cdff57c..7ba0b225 100644 --- a/unix/vncpasswd/vncpasswd.cxx +++ b/unix/vncpasswd/vncpasswd.cxx @@ -102,14 +102,13 @@ int main(int argc, char** argv) 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; } diff --git a/unix/vncviewer/vncviewer.cxx b/unix/vncviewer/vncviewer.cxx index f3a5e01a..8b741c0d 100644 --- a/unix/vncviewer/vncviewer.cxx +++ b/unix/vncviewer/vncviewer.cxx @@ -328,14 +328,13 @@ int main(int argc, char** argv) // 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; }