From b30ae7facbdf8273f34f5d67d3d2e9c81db75576 Mon Sep 17 00:00:00 2001
From: Constantin Kaplinsky <const@tightvnc.com>
Date: Thu, 25 May 2006 05:04:46 +0000
Subject: Migrating to new directory structure adopted from the RealVNC's
 source tree. More changes will follow.

git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@590 3789f03b-4d11-0410-bbf8-ca57d06f2519
---
 unix/vncpasswd/Makefile.in   |  18 ++++++
 unix/vncpasswd/vncpasswd.cxx | 138 +++++++++++++++++++++++++++++++++++++++++++
 unix/vncpasswd/vncpasswd.man |  43 ++++++++++++++
 3 files changed, 199 insertions(+)
 create mode 100644 unix/vncpasswd/Makefile.in
 create mode 100644 unix/vncpasswd/vncpasswd.cxx
 create mode 100644 unix/vncpasswd/vncpasswd.man

(limited to 'unix/vncpasswd')

diff --git a/unix/vncpasswd/Makefile.in b/unix/vncpasswd/Makefile.in
new file mode 100644
index 00000000..927a7b92
--- /dev/null
+++ b/unix/vncpasswd/Makefile.in
@@ -0,0 +1,18 @@
+
+SRCS = vncpasswd.cxx
+
+OBJS = vncpasswd.o
+
+program = vncpasswd
+
+DEP_LIBS = ../rfb/librfb.a
+
+DIR_CPPFLAGS = -I$(top_srcdir)
+
+all:: $(program)
+
+$(program): $(OBJS) $(DEP_LIBS)
+	rm -f $(program)
+	$(CXXLD) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(DEP_LIBS) $(LIBS)
+
+# followed by boilerplate.mk
diff --git a/unix/vncpasswd/vncpasswd.cxx b/unix/vncpasswd/vncpasswd.cxx
new file mode 100644
index 00000000..e8898792
--- /dev/null
+++ b/unix/vncpasswd/vncpasswd.cxx
@@ -0,0 +1,138 @@
+/* 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
+ * (at your option) any later version.
+ * 
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ * USA.
+ */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <rfb/Password.h>
+#include <rfb/util.h>
+
+#include <termios.h>
+
+
+using namespace rfb;
+
+char* prog;
+
+static void usage()
+{
+  fprintf(stderr,"usage: %s [file]\n",prog);
+  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];
+
+  char* fname = 0;
+
+  for (int i = 1; i < argc; i++) {
+    if (strcmp(argv[i], "-q") == 0) { // allowed for backwards compatibility
+    } else if (argv[i][0] == '-') {
+      usage();
+    } else if (!fname) {
+      fname = argv[i];
+    } else {
+      usage();
+    }
+  }
+
+  if (!fname) {
+    if (!getenv("HOME")) {
+      fprintf(stderr,"HOME is not set\n");
+      exit(1);
+    }
+    fname = new char[strlen(getenv("HOME")) + 20];
+    sprintf(fname, "%s/.vnc", getenv("HOME"));
+    mkdir(fname, 0777);
+    sprintf(fname, "%s/.vnc/passwd", getenv("HOME"));
+  }
+
+  while (true) {
+    PlainPasswd passwd(getpassword("Password:"));
+    if (!passwd.buf) {
+      perror("getpassword error");
+      exit(1);
+    }   
+    if (strlen(passwd.buf) < 6) {
+      if (strlen(passwd.buf) == 0) {
+        fprintf(stderr,"Password not changed\n");
+        exit(1);
+      }
+      fprintf(stderr,"Password must be at least 6 characters - try again\n");
+      continue;
+    }
+
+    PlainPasswd passwd2(getpassword("Verify:"));
+    if (!passwd2.buf) {
+      perror("getpass error");
+      exit(1);
+    }   
+    if (strcmp(passwd.buf, passwd2.buf) != 0) {
+      fprintf(stderr,"Passwords don't match - try again\n");
+      continue;
+    }
+
+    FILE* fp = fopen(fname,"w");
+    if (!fp) {
+      fprintf(stderr,"Couldn't open %s for writing\n",fname);
+      exit(1);
+    }
+    chmod(fname, S_IRUSR|S_IWUSR);
+
+    ObfuscatedPasswd obfuscated(passwd);
+
+    if (fwrite(obfuscated.buf, obfuscated.length, 1, fp) != 1) {
+      fprintf(stderr,"Writing to %s failed\n",fname);
+      exit(1);
+    }
+
+    fclose(fp);
+
+    return 0;
+  }
+}
diff --git a/unix/vncpasswd/vncpasswd.man b/unix/vncpasswd/vncpasswd.man
new file mode 100644
index 00000000..8fd68745
--- /dev/null
+++ b/unix/vncpasswd/vncpasswd.man
@@ -0,0 +1,43 @@
+.TH vncpasswd 1 "05 May 2006" "TightVNC" "Virtual Network Computing"
+.SH NAME
+vncpasswd \- change a VNC password
+.SH SYNOPSIS
+.B vncpasswd
+.RI [ passwd-file ]
+.SH DESCRIPTION
+.B vncpasswd
+allows you to set the password used to access VNC desktops.  It stores an
+obfuscated version of the password in the given file (default
+$HOME/.vnc/passwd).  The \fBvncserver\fP script runs \fBvncpasswd\fP the first
+time you start a VNC desktop, and invokes \fBXvnc\fP with the appropriate
+\fB\-rfbauth\fP option.  \fBvncviewer\fP can also be given a password file to
+use via the \fB\-passwd\fP option.
+
+The password must be at least six characters long, and only the first eight
+characters are significant.  Note that the stored password is \fBnot\fP
+encrypted securely - anyone who has access to this file can trivially find out
+the plaintext password, so \fBvncpasswd\fP always sets appropriate permissions
+(read and write only by the owner).  However, when accessing a VNC desktop a
+challenge-response mechanism is used over the wire making it hard for anyone to
+crack the password simply by snooping on the network.
+
+.SH FILES
+.TP
+$HOME/.vnc/passwd
+Default location of the VNC password file.
+
+.SH SEE ALSO
+.BR vncviewer (1),
+.BR vncserver (1),
+.BR Xvnc (1)
+.BR vncconfig (1),
+.br
+http://www.tightvnc.com
+
+.SH AUTHOR
+Tristan Richardson, RealVNC Ltd.
+
+VNC was originally developed by the RealVNC team while at Olivetti
+Research Ltd / AT&T Laboratories Cambridge.  TightVNC additions was
+implemented by Constantin Kaplinsky. Many other people participated in
+development, testing and support.
-- 
cgit v1.2.3