From: DRC Date: Fri, 9 Jul 2010 19:48:26 +0000 (+0000) Subject: Reuse the getpasswd() function in filter mode so that the new line is stripped from... X-Git-Tag: v1.0.90~227 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c1afba7522f8b50f16308499172bc511f8211a55;p=tigervnc.git 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 --- 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)