On Wed, Sep 11, 2024 at 01:51:29PM +0200, Jakub Palacky wrote: > 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@xxxxxxxxxx> > --- > meson.build | 6 ++++++ > src/meson.build | 1 + > src/util/virutil.c | 6 ++++++ > 3 files changed, 13 insertions(+) > > diff --git a/meson.build b/meson.build > index 297fbfae48..699a65c7e8 100644 > --- a/meson.build > +++ b/meson.build > @@ -954,6 +954,11 @@ if blkid_dep.found() > conf.set('WITH_BLKID', 1) > endif > > +bsd_dep = dependency('libbsd', required: false) > +if bsd_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': bsd_dep.found(), > 'libiscsi': libiscsi_dep.found(), > 'libkvm': libkvm_dep.found(), > 'libnbd': libnbd_dep.found(), > diff --git a/src/meson.build b/src/meson.build > index 8cce42c7ad..30ae34646e 100644 > --- a/src/meson.build > +++ b/src/meson.build > @@ -9,6 +9,7 @@ src_dep = declare_dependency( > dependencies: [ > glib_dep, > libxml_dep, > + bsd_dep, > ], > include_directories: [ > libvirt_inc, > diff --git a/src/util/virutil.c b/src/util/virutil.c > index 6c89a48e51..2e07372198 100644 > --- a/src/util/virutil.c > +++ b/src/util/virutil.c > @@ -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,8 @@ char *virGetPassword(void) > } > > return g_string_free(pw, FALSE); > +#elif WITH_LIBBSD /* !WIN32 */ > + return readpassphrase("", g_new0(char, 1024), 1024, 0); THe docs say that readpassphrase may return NULL on error, in which case the result of "g_new0" here will be leaked. You need to stash the g_new0 return pointer, and free it if readpassphrase returns NULL. > #else /* !WIN32 */ > return g_strdup(getpass("")); > #endif /* ! WIN32 */ > -- > 2.46.0 > With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|