Pino Toscano
2016-Jun-23 09:09 UTC
[Libguestfs] [PATCH] p2v: improve error message for sudo with password
Print a better error message when the non-root user on the conversion server requires a password to use sudo, and p2v is told to use sudo. See also RHZ#1340809. --- p2v/ssh.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/p2v/ssh.c b/p2v/ssh.c index 76a6827..97d76ae 100644 --- a/p2v/ssh.c +++ b/p2v/ssh.c @@ -97,6 +97,7 @@ static void free_regexps (void) __attribute__((destructor)); static pcre *password_re; static pcre *ssh_message_re; +static pcre *sudo_password_re; static pcre *prompt_re; static pcre *version_re; static pcre *feature_libguestfs_rewrite_re; @@ -140,6 +141,7 @@ compile_regexps (void) COMPILE (password_re, "password:", 0); COMPILE (ssh_message_re, "(ssh: .*)", 0); + COMPILE (sudo_password_re, "sudo: a password is required", 0); /* The magic synchronization strings all match this expression. See * start_ssh function below. */ @@ -160,6 +162,7 @@ free_regexps (void) { pcre_free (password_re); pcre_free (ssh_message_re); + pcre_free (sudo_password_re); pcre_free (prompt_re); pcre_free (version_re); pcre_free (feature_libguestfs_rewrite_re); @@ -532,6 +535,7 @@ test_connection (struct config *config) (mexp_regexp[]) { { 100, .re = version_re }, { 101, .re = prompt_re }, + { 102, .re = sudo_password_re }, { 0 } }, ovector, ovecsize)) { case 100: /* Got version string. */ @@ -546,6 +550,11 @@ test_connection (struct config *config) case 101: /* Got the prompt. */ goto end_of_version; + case 102: + mexp_close (h); + set_ssh_error ("sudo for user '%s' requires a password", config->username); + return -1; + case MEXP_EOF: mexp_close (h); set_ssh_error ("unexpected end of file waiting virt-v2v --version output"); -- 2.5.5
Richard W.M. Jones
2016-Jun-23 09:13 UTC
Re: [Libguestfs] [PATCH] p2v: improve error message for sudo with password
On Thu, Jun 23, 2016 at 11:09:23AM +0200, Pino Toscano wrote:> Print a better error message when the non-root user on the conversion > server requires a password to use sudo, and p2v is told to use sudo. > > See also RHZ#1340809. > --- > p2v/ssh.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/p2v/ssh.c b/p2v/ssh.c > index 76a6827..97d76ae 100644 > --- a/p2v/ssh.c > +++ b/p2v/ssh.c > @@ -97,6 +97,7 @@ static void free_regexps (void) __attribute__((destructor)); > > static pcre *password_re; > static pcre *ssh_message_re; > +static pcre *sudo_password_re; > static pcre *prompt_re; > static pcre *version_re; > static pcre *feature_libguestfs_rewrite_re; > @@ -140,6 +141,7 @@ compile_regexps (void) > > COMPILE (password_re, "password:", 0); > COMPILE (ssh_message_re, "(ssh: .*)", 0); > + COMPILE (sudo_password_re, "sudo: a password is required", 0); > /* The magic synchronization strings all match this expression. See > * start_ssh function below. > */ > @@ -160,6 +162,7 @@ free_regexps (void) > { > pcre_free (password_re); > pcre_free (ssh_message_re); > + pcre_free (sudo_password_re); > pcre_free (prompt_re); > pcre_free (version_re); > pcre_free (feature_libguestfs_rewrite_re); > @@ -532,6 +535,7 @@ test_connection (struct config *config) > (mexp_regexp[]) { > { 100, .re = version_re }, > { 101, .re = prompt_re }, > + { 102, .re = sudo_password_re }, > { 0 } > }, ovector, ovecsize)) { > case 100: /* Got version string. */ > @@ -546,6 +550,11 @@ test_connection (struct config *config) > case 101: /* Got the prompt. */ > goto end_of_version; > > + case 102: > + mexp_close (h); > + set_ssh_error ("sudo for user '%s' requires a password", config->username); > + return -1; > + > case MEXP_EOF: > mexp_close (h); > set_ssh_error ("unexpected end of file waiting virt-v2v --version output"); > -- > 2.5.5 >This is pretty much the same as my patch, so ACK. However it did lead me to think that if we're matching on error messages now, we need to also send a "LANG=C" command (which is not so simple). And from there I wondered if we can rely on people using bash (or other Bourne-like shell). Currently we send 'export PS1=...' which will totally fail for anyone using csh/tcsh (I'm not sure about ksh and zsh). So I'm still looking at this. However please push the above patch anyway. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
Reasonably Related Threads
- [PATCH] p2v: Test for sudo requiring a password first (RHBZ#1500673).
- [PATCH 0/7] p2v: Multiple improvements to the look of virt-p2v.
- [PATCH 0/2] Remove virt-p2v from libguestfs
- [PATCH 0/4] p2v: Send ^C to remote end to cancel the conversion.
- [PATCH] p2v: check results of strndup and sscanf