[patch] make vncpasswd create ~/.vnc if it doesn't exist

Tim Waugh twaugh "at" redhat.com
Mon, 03 Sep 2001 18:41:31 +0000


Here is a patch that makes vncpasswd create ~/.vnc if it doesn't
exist, rather than failing with a less than obvious error message.

Tim.
*/

--- vnc_unixsrc/vncpasswd/vncpasswd.c.vncuserdir	Tue Aug 17 12:31:42 1999
+++ vnc_unixsrc/vncpasswd/vncpasswd.c	Mon Sep  3 18:09:06 2001
@@ -24,9 +24,12 @@
  *              anyway.
  */
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 #include <unistd.h>
 #include "vncauth.h"
 
@@ -38,6 +41,7 @@
 int main(int argc, char *argv[]) {
   char *passwd;
   char *passwd1;
+  char passwdDir[256];
   char passwdFile[256];
   int i;
 
@@ -46,7 +50,8 @@
 	  fprintf(stderr,"Error: no HOME environment variable\n");
 	  exit(1);
       }
-      sprintf(passwdFile,"%s/.vnc/passwd",getenv("HOME"));
+      sprintf(passwdDir,"%s/.vnc",getenv("HOME"));
+      sprintf(passwdFile,"%s/passwd",passwdDir);
 
   } else if (argc == 2) {
 
@@ -78,6 +83,12 @@
     }
 
     if (strcmp(passwd1, passwd) == 0) {
+      if (mkdir (passwdDir, (S_IRWXU | S_IRGRP | S_IXGRP |
+			     S_IROTH | S_IXOTH)) == -1 &&
+	  errno != EEXIST) {
+	perror ("~/.vnc");
+	exit (1);
+      }
       if (vncEncryptAndStorePasswd(passwd, passwdFile) != 0) {
 	fprintf(stderr,"Cannot write password file %s\n",passwdFile);
 	exit(1);
---------------------------------------------------------------------
To unsubscribe, send a message with the line: unsubscribe vnc-list
to majordomo "at" uk.research.att.com
See also: http://www.uk.research.att.com/vnc/intouch.html
---------------------------------------------------------------------