mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
util/virutil: Use readpassphrase when libbsd is available
When libbsd is available, use the preferred readpassphrase() function isntead of getpass() as the getpass() function has been marked as obsolete and shouldnt be used Signed-off-by: Jakub Palacky <jpalacky@redhat.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
94e8a5b650
commit
317139a316
@ -954,6 +954,11 @@ if blkid_dep.found()
|
||||
conf.set('WITH_BLKID', 1)
|
||||
endif
|
||||
|
||||
libbsd_dep = dependency('libbsd', required: false)
|
||||
if libbsd_dep.found()
|
||||
conf.set('WITH_LIBBSD', 1)
|
||||
endif
|
||||
|
||||
capng_dep = dependency('libcap-ng', required: get_option('capng'))
|
||||
if capng_dep.found()
|
||||
conf.set('WITH_CAPNG', 1)
|
||||
@ -2335,6 +2340,7 @@ libs_summary = {
|
||||
'dlopen': dlopen_dep.found(),
|
||||
'fuse': fuse_dep.found(),
|
||||
'glusterfs': glusterfs_dep.found(),
|
||||
'libbsd': libbsd_dep.found(),
|
||||
'libiscsi': libiscsi_dep.found(),
|
||||
'libkvm': libkvm_dep.found(),
|
||||
'libnbd': libnbd_dep.found(),
|
||||
|
@ -194,6 +194,7 @@ virt_util_lib = static_library(
|
||||
devmapper_dep,
|
||||
gnutls_dep,
|
||||
intl_dep,
|
||||
libbsd_dep,
|
||||
libm_dep,
|
||||
libnl_dep,
|
||||
libutil_dep,
|
||||
|
@ -31,6 +31,10 @@
|
||||
# include <conio.h>
|
||||
#endif /* WIN32 */
|
||||
|
||||
#ifdef WITH_LIBBSD
|
||||
# include <bsd/readpassphrase.h>
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
# include <sys/sysmacros.h>
|
||||
#endif
|
||||
@ -1773,6 +1777,19 @@ char *virGetPassword(void)
|
||||
}
|
||||
|
||||
return g_string_free(pw, FALSE);
|
||||
#elif WITH_LIBBSD /* !WIN32 */
|
||||
# ifndef PASS_MAX
|
||||
# define PASS_MAX 1024
|
||||
# endif
|
||||
char *pass = NULL;
|
||||
g_autofree char *buffer = g_new0(char, PASS_MAX);
|
||||
|
||||
pass = readpassphrase("", buffer, PASS_MAX, 0);
|
||||
if (pass == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return g_steal_pointer(&buffer);
|
||||
#else /* !WIN32 */
|
||||
return g_strdup(getpass(""));
|
||||
#endif /* ! WIN32 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user