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 a8f3afd..d21ea94 100644
--- a/unix/vncpasswd/vncpasswd.cxx
+++ b/unix/vncpasswd/vncpasswd.cxx
@@ -54,7 +54,7 @@
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 @@
// 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)