#include <libxml/parser.h>
#include <libxml/xpath.h>
-#include "getpass.h"
#ifdef WITH_CURL
# include <curl/curl.h>
if (fflush(stdout) != 0)
return -1;
- bufptr = getpass("");
- if (!bufptr)
- return -1;
+ bufptr = virGetPassword();
+ if (STREQ(bufptr, ""))
+ VIR_FREE(bufptr);
break;
default:
}
if (cred[i].type != VIR_CRED_EXTERNAL) {
- cred[i].result = g_strdup(STREQ(bufptr, "") && cred[i].defresult ? cred[i].defresult : bufptr);
+ cred[i].result = bufptr ? bufptr : g_strdup(cred[i].defresult ? cred[i].defresult : "");
cred[i].resultlen = strlen(cred[i].result);
}
}
virGetGroupName;
virGetHostname;
virGetHostnameQuiet;
+virGetPassword;
virGetSelfLastChanged;
virGetSystemPageSize;
virGetSystemPageSizeKB;
#include <poll.h>
#include <sys/stat.h>
+#ifdef WIN32
+# include <conio.h>
+#endif /* WIN32 */
+
#ifdef MAJOR_IN_MKDEV
# include <sys/mkdev.h>
#elif MAJOR_IN_SYSMACROS
VIR_DIR_CLOSE(driDir);
return ret;
}
+
+/*
+ * Get a password from the console input stream.
+ * The caller must free the returned password.
+ *
+ * Returns: the password, or NULL
+ */
+char *virGetPassword(void)
+{
+#ifdef WIN32
+ GString *pw = g_string_new("");
+
+ while (1) {
+ char c = _getch();
+ if (c == '\r')
+ break;
+
+ g_string_append_c(pw, c);
+ }
+
+ return g_string_free(pw, FALSE);
+#else /* !WIN32 */
+ return g_strdup(getpass(""));
+#endif /* ! WIN32 */
+}
*/
#define VIR_ASSIGN_IS_OVERFLOW(lvalue, rvalue) \
(((lvalue) = (rvalue)) != (rvalue))
+
+char *virGetPassword(void);
vshPrint(ctl, "%s", _("Enter new value for secret:"));
fflush(stdout);
- if (!(file_buf = getpass(""))) {
+ if (!(file_buf = virGetPassword())) {
vshError(ctl, "%s", _("Failed to read secret"));
return false;
}