Initial revision
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/vncpasswd/Makefile.in b/vncpasswd/Makefile.in
new file mode 100644
index 0000000..fb625e0
--- /dev/null
+++ b/vncpasswd/Makefile.in
@@ -0,0 +1,18 @@
+
+SRCS = vncpasswd.cxx
+
+OBJS = vncpasswd.o
+
+program = vncpasswd
+
+DEP_LIBS = ../rfb/librfb.a # ../network/libnetwork.a ../rdr/librdr.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/vncpasswd/vncpasswd.cxx b/vncpasswd/vncpasswd.cxx
new file mode 100644
index 0000000..c8dd777
--- /dev/null
+++ b/vncpasswd/vncpasswd.cxx
@@ -0,0 +1,119 @@
+/* Copyright (C) 2002-2003 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/vncAuth.h>
+#include <rfb/util.h>
+
+using namespace rfb;
+
+char* prog;
+
+static void usage()
+{
+ fprintf(stderr,"usage: %s [file]\n",prog);
+ exit(1);
+}
+
+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) {
+ char* passwd = getpass("Password: ");
+ if (!passwd) {
+ perror("getpass error");
+ exit(1);
+ }
+ if (strlen(passwd) < 6) {
+ if (strlen(passwd) == 0) {
+ fprintf(stderr,"Password not changed\n");
+ exit(1);
+ }
+ fprintf(stderr,"Password must be at least 6 characters - try again\n");
+ continue;
+ }
+
+ if (strlen(passwd) > 8)
+ passwd[8] = '\0';
+
+ CharArray passwdCopy(strDup(passwd));
+
+ passwd = getpass("Verify: ");
+ if (!passwd) {
+ perror("getpass error");
+ exit(1);
+ }
+ if (strlen(passwd) > 8)
+ passwd[8] = '\0';
+
+ if (strcmp(passwdCopy.buf, passwd) != 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);
+
+ vncAuthObfuscatePasswd(passwd);
+
+ if (fwrite(passwd, 8, 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;
+ }
+}
diff --git a/vncpasswd/vncpasswd.man b/vncpasswd/vncpasswd.man
new file mode 100644
index 0000000..ab5e761
--- /dev/null
+++ b/vncpasswd/vncpasswd.man
@@ -0,0 +1,42 @@
+.TH vncpasswd 1 "29 July 2003" "RealVNC Ltd" "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.realvnc.com
+
+.SH AUTHOR
+Tristan Richardson, RealVNC Ltd.
+
+VNC was originally developed by the RealVNC team while at Olivetti Research Ltd
+/ AT&T Laboratories Cambridge. It is now being maintained by RealVNC Ltd. See
+http://www.realvnc.com for details.