From: Constantin Kaplinsky Date: Fri, 5 May 2006 11:45:47 +0000 (+0000) Subject: vncpasswd utility merged with VNC 4.1.1 code. X-Git-Tag: v0.0.90~384^2~312^2~14 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=64a943b6772cc7ca3abc1fccd17400ee730f7297;p=tigervnc.git vncpasswd utility merged with VNC 4.1.1 code. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/branches/merge-with-vnc-4.1.1@544 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- diff --git a/vncpasswd/Makefile.in b/vncpasswd/Makefile.in index fb625e0b..927a7b92 100644 --- a/vncpasswd/Makefile.in +++ b/vncpasswd/Makefile.in @@ -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) diff --git a/vncpasswd/vncpasswd.cxx b/vncpasswd/vncpasswd.cxx index c8dd777d..e8898792 100644 --- a/vncpasswd/vncpasswd.cxx +++ b/vncpasswd/vncpasswd.cxx @@ -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 @@ -21,9 +21,12 @@ #include #include #include -#include +#include #include +#include + + 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; } } diff --git a/vncpasswd/vncpasswd.man b/vncpasswd/vncpasswd.man index 86ea6cb6..8fd68745 100644 --- a/vncpasswd/vncpasswd.man +++ b/vncpasswd/vncpasswd.man @@ -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