diff options
author | DRC <dcommander@users.sourceforge.net> | 2010-07-09 19:48:26 +0000 |
---|---|---|
committer | DRC <dcommander@users.sourceforge.net> | 2010-07-09 19:48:26 +0000 |
commit | c1afba7522f8b50f16308499172bc511f8211a55 (patch) | |
tree | 404d0c453b564f0bceaf4d525718697d5583723b | |
parent | 7f9ea27ec88dc0eaadc4cb6f9397f61a9fbad521 (diff) | |
download | tigervnc-c1afba7522f8b50f16308499172bc511f8211a55.tar.gz tigervnc-c1afba7522f8b50f16308499172bc511f8211a55.zip |
Reuse the getpasswd() function in filter mode so that the new line is stripped from the input
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4086 3789f03b-4d11-0410-bbf8-ca57d06f2519
-rw-r--r-- | unix/vncpasswd/vncpasswd.cxx | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/unix/vncpasswd/vncpasswd.cxx b/unix/vncpasswd/vncpasswd.cxx index a8f3afd0..d21ea942 100644 --- a/unix/vncpasswd/vncpasswd.cxx +++ b/unix/vncpasswd/vncpasswd.cxx @@ -54,7 +54,7 @@ static void enableEcho(bool enable) { static char* getpassword(const char* prompt) { PlainPasswd buf(256); - fputs(prompt, stdout); + if (prompt) fputs(prompt, stdout); enableEcho(false); char* result = fgets(buf.buf, 256, stdin); enableEcho(true); @@ -68,15 +68,16 @@ static char* getpassword(const char* prompt) { // Reads password from stdin and prints encrypted password to stdout. static int encrypt_pipe() { - PlainPasswd buf(256); - fgets(buf.buf, 256, stdin); - ObfuscatedPasswd obfuscated(buf); - //fputs(prompt, stdout); - if (fwrite(obfuscated.buf, obfuscated.length, 1, stdout) != 1) { - fprintf(stderr,"Writing to stdout failed\n"); - return 1; + char *result = getpassword(NULL); + if (result) { + ObfuscatedPasswd obfuscated(result); + if (fwrite(obfuscated.buf, obfuscated.length, 1, stdout) != 1) { + fprintf(stderr,"Writing to stdout failed\n"); + return 1; + } + return 0; } - return 0; + else return 1; } int main(int argc, char** argv) |