#include <shlobj.h>
#endif
-int gethomedir(char **dirp)
+int getvnchomedir(char **dirp)
{
#ifndef WIN32
char *homedir, *dir;
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)
delete [] dir;
return -1;
}
-
-
+ memcpy(dir+strlen(dir), (TCHAR *)"\\vnc\\\0", 6);
#endif
-
*dirp = dir;
return 0;
}
#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:
* 0 - Success
* -1 - Failure
*/
-int gethomedir(char **dirp);
+int getvnchomedir(char **dirp);
#endif /* OS_OS_H */
{
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()
< 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)
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;
}
// 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;
}