]> source.dussan.org Git - tigervnc.git/commitdiff
vncpasswd utility merged with VNC 4.1.1 code.
authorConstantin Kaplinsky <const@tightvnc.com>
Fri, 5 May 2006 11:45:47 +0000 (11:45 +0000)
committerConstantin Kaplinsky <const@tightvnc.com>
Fri, 5 May 2006 11:45:47 +0000 (11:45 +0000)
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/branches/merge-with-vnc-4.1.1@544 3789f03b-4d11-0410-bbf8-ca57d06f2519

vncpasswd/Makefile.in
vncpasswd/vncpasswd.cxx
vncpasswd/vncpasswd.man

index fb625e0bdc42e63a8f9babe72bb20018e665845c..927a7b9209c6565b541165bb9300f0523aaf06a3 100644 (file)
@@ -5,7 +5,7 @@ OBJS = vncpasswd.o
 
 program = vncpasswd
 
-DEP_LIBS = ../rfb/librfb.a # ../network/libnetwork.a ../rdr/librdr.a
+DEP_LIBS = ../rfb/librfb.a
 
 DIR_CPPFLAGS = -I$(top_srcdir)
 
index c8dd777d533e9850793f8336def311c212e21b8c..e889879204e2afdec597bfbe76bc674be1f3b0b7 100644 (file)
@@ -1,5 +1,5 @@
-/* Copyright (C) 2002-2003 RealVNC Ltd.  All Rights Reserved.
- *    
+/* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
+ * 
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
-#include <rfb/vncAuth.h>
+#include <rfb/Password.h>
 #include <rfb/util.h>
 
+#include <termios.h>
+
+
 using namespace rfb;
 
 char* prog;
@@ -34,6 +37,33 @@ static void usage()
   exit(1);
 }
 
+
+static void enableEcho(bool enable) {
+  termios attrs;
+  tcgetattr(fileno(stdin), &attrs);
+  if (enable)
+    attrs.c_lflag |= ECHO;
+  else
+    attrs.c_lflag &= ~ECHO;
+  attrs.c_lflag |= ECHONL;
+  tcsetattr(fileno(stdin), TCSAFLUSH, &attrs);
+}
+
+static char* getpassword(const char* prompt) {
+  PlainPasswd buf(256);
+  fputs(prompt, stdout);
+  enableEcho(false);
+  char* result = fgets(buf.buf, 256, stdin);
+  enableEcho(true);
+  if (result) {
+    if (result[strlen(result)-1] == '\n')
+      result[strlen(result)-1] = 0;
+    return buf.takeBuf();
+  }
+  return 0;
+}
+
+
 int main(int argc, char** argv)
 {
   prog = argv[0];
@@ -63,13 +93,13 @@ int main(int argc, char** argv)
   }
 
   while (true) {
-    char* passwd = getpass("Password: ");
-    if (!passwd) {
-      perror("getpass error");
+    PlainPasswd passwd(getpassword("Password:"));
+    if (!passwd.buf) {
+      perror("getpassword error");
       exit(1);
     }   
-    if (strlen(passwd) < 6) {
-      if (strlen(passwd) == 0) {
+    if (strlen(passwd.buf) < 6) {
+      if (strlen(passwd.buf) == 0) {
         fprintf(stderr,"Password not changed\n");
         exit(1);
       }
@@ -77,20 +107,12 @@ int main(int argc, char** argv)
       continue;
     }
 
-    if (strlen(passwd) > 8)
-      passwd[8] = '\0';
-
-    CharArray passwdCopy(strDup(passwd));
-
-    passwd = getpass("Verify: ");
-    if (!passwd) {
+    PlainPasswd passwd2(getpassword("Verify:"));
+    if (!passwd2.buf) {
       perror("getpass error");
       exit(1);
     }   
-    if (strlen(passwd) > 8)
-      passwd[8] = '\0';
-
-    if (strcmp(passwdCopy.buf, passwd) != 0) {
+    if (strcmp(passwd.buf, passwd2.buf) != 0) {
       fprintf(stderr,"Passwords don't match - try again\n");
       continue;
     }
@@ -102,18 +124,15 @@ int main(int argc, char** argv)
     }
     chmod(fname, S_IRUSR|S_IWUSR);
 
-    vncAuthObfuscatePasswd(passwd);
+    ObfuscatedPasswd obfuscated(passwd);
 
-    if (fwrite(passwd, 8, 1, fp) != 1) {
+    if (fwrite(obfuscated.buf, obfuscated.length, 1, fp) != 1) {
       fprintf(stderr,"Writing to %s failed\n",fname);
       exit(1);
     }
 
     fclose(fp);
 
-    for (unsigned int i = 0; i < strlen(passwd); i++)
-      passwd[i] = passwdCopy.buf[i] = 0;
-
     return 0;
   }
 }
index 86ea6cb63537e3afd7715433cfc16c72392df99d..8fd6874510d75860b4293ab61e5e03e169bba88f 100644 (file)
@@ -1,4 +1,4 @@
-.TH vncpasswd 1 "30 December 2004" "TightVNC" "Virtual Network Computing"
+.TH vncpasswd 1 "05 May 2006" "TightVNC" "Virtual Network Computing"
 .SH NAME
 vncpasswd \- change a VNC password
 .SH SYNOPSIS