Browse Source

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
tags/v0.0.90
Constantin Kaplinsky 18 years ago
parent
commit
64a943b677
3 changed files with 45 additions and 26 deletions
  1. 1
    1
      vncpasswd/Makefile.in
  2. 43
    24
      vncpasswd/vncpasswd.cxx
  3. 1
    1
      vncpasswd/vncpasswd.man

+ 1
- 1
vncpasswd/Makefile.in View 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)


+ 43
- 24
vncpasswd/vncpasswd.cxx View 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
@@ -21,9 +21,12 @@
#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;
}
}

+ 1
- 1
vncpasswd/vncpasswd.man View 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

Loading…
Cancel
Save