[libvirt] [PATCH v2] Correct include-password option and rewrite domdisplay

The 'virsh domdisplay' command is able to display the password configured for spice, but it was missing for vnc type graphics. Also, there were some inconsistencies that are cleaned now. --- tools/virsh-domain.c | 74 +++++++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index cc47383..cc5c830 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -7038,8 +7038,11 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) /* Attempt to grab our display info */ for (iter = 0; scheme[iter] != NULL; iter++) { /* Create our XPATH lookup for the current display's port */ - virAsprintf(&xpath, "string(/domain/devices/graphics[@type='%s']" - "/@port)", scheme[iter]); + virAsprintf(&xpath, + "string(/domain/devices/graphics[@type='%s']" + "/@port)", + scheme[iter]); + if (!xpath) { virReportOOMError(); goto cleanup; @@ -7056,8 +7059,10 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) continue; /* Create our XPATH lookup for the current display's address */ - virAsprintf(&xpath, "string(/domain/devices/graphics[@type='%s']" - "/@listen)", scheme[iter]); + virAsprintf(&xpath, + "string(/domain/devices/graphics[@type='%s']" + "/@listen)", + scheme[iter]); if (!xpath) { virReportOOMError(); goto cleanup; @@ -7069,14 +7074,36 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) listen_addr = virXPathString(xpath, ctxt); VIR_FREE(xpath); + /* We can query this info for all the graphics types since we'll + * get nothing for the unsupported ones (just rdp for now) */ + if (vshCommandOptBool(cmd, "include-password")) { + /* Create our XPATH lookup for the password */ + virAsprintf(&xpath, + "string(/domain/devices/graphics" + "[@type='%s']/@passwd)", + scheme[iter]); + + if (!xpath) { + virReportOOMError(); + goto cleanup; + } + + /* Attempt to get the password */ + passwd = virXPathString(xpath, ctxt); + VIR_FREE(xpath); + } + /* Per scheme data mangling */ if (STREQ(scheme[iter], "vnc")) { - /* VNC protocol handlers take their port number as 'port' - 5900 */ + /* VNC protocol handlers take their port number as + * 'port' - 5900 */ port -= 5900; } else if (STREQ(scheme[iter], "spice")) { /* Create our XPATH lookup for the SPICE TLS Port */ - virAsprintf(&xpath, "string(/domain/devices/graphics[@type='%s']" - "/@tlsPort)", scheme[iter]); + virAsprintf(&xpath, + "string(/domain/devices/graphics[@type='%s']" + "/@tlsPort)", + scheme[iter]); if (!xpath) { virReportOOMError(); goto cleanup; @@ -7087,25 +7114,17 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) VIR_FREE(xpath); if (tmp) tls_port = 0; - - if (vshCommandOptBool(cmd, "include-password")) { - /* Create our XPATH lookup for the SPICE password */ - virAsprintf(&xpath, "string(/domain/devices/graphics" - "[@type='%s']/@passwd)", scheme[iter]); - if (!xpath) { - virReportOOMError(); - goto cleanup; - } - - /* Attempt to get the SPICE password */ - passwd = virXPathString(xpath, ctxt); - VIR_FREE(xpath); - } } /* Build up the full URI, starting with the scheme */ virBufferAsprintf(&buf, "%s://", scheme[iter]); + /* There is no user, so just append password if there's any */ + if (passwd) { + virBufferAsprintf(&buf, ":%s@", passwd); + VIR_FREE(passwd); + } + /* Then host name or IP */ if (!listen_addr || STREQ((const char *)listen_addr, "0.0.0.0")) virBufferAddLit(&buf, "localhost"); @@ -7115,20 +7134,11 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) VIR_FREE(listen_addr); /* Add the port */ - if (STREQ(scheme[iter], "spice")) - virBufferAsprintf(&buf, "?port=%d", port); - else - virBufferAsprintf(&buf, ":%d", port); + virBufferAsprintf(&buf, ":%d", port); /* TLS Port */ if (tls_port) - virBufferAsprintf(&buf, "&tls-port=%d", tls_port); - - /* Password */ - if (passwd) { - virBufferAsprintf(&buf, "&password=%s", passwd); - VIR_FREE(passwd); - } + virBufferAsprintf(&buf, "?tls-port=%d", tls_port); /* Ensure we can print our URI */ if (virBufferError(&buf)) { -- 1.8.0

On 11/22/12 11:34, Martin Kletzander wrote:
The 'virsh domdisplay' command is able to display the password configured for spice, but it was missing for vnc type graphics. Also, there were some inconsistencies that are cleaned now. --- tools/virsh-domain.c | 74 +++++++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 32 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index cc47383..cc5c830 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c
@@ -7069,14 +7074,36 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) listen_addr = virXPathString(xpath, ctxt); VIR_FREE(xpath);
+ /* We can query this info for all the graphics types since we'll + * get nothing for the unsupported ones (just rdp for now) */ + if (vshCommandOptBool(cmd, "include-password")) { + /* Create our XPATH lookup for the password */ + virAsprintf(&xpath, + "string(/domain/devices/graphics" + "[@type='%s']/@passwd)", + scheme[iter]);
The usual way is to check the return value of virAsprintf here instead of checking the allocated memory.
+ + if (!xpath) { + virReportOOMError(); + goto cleanup;
Hm, a no_memory label would decrease the line count somewhat, but that's not necessary ...
+ } + + /* Attempt to get the password */ + passwd = virXPathString(xpath, ctxt); + VIR_FREE(xpath); + } + /* Per scheme data mangling */ if (STREQ(scheme[iter], "vnc")) { - /* VNC protocol handlers take their port number as 'port' - 5900 */ + /* VNC protocol handlers take their port number as + * 'port' - 5900 */ port -= 5900; } else if (STREQ(scheme[iter], "spice")) { /* Create our XPATH lookup for the SPICE TLS Port */ - virAsprintf(&xpath, "string(/domain/devices/graphics[@type='%s']" - "/@tlsPort)", scheme[iter]); + virAsprintf(&xpath, + "string(/domain/devices/graphics[@type='%s']" + "/@tlsPort)", + scheme[iter]);
Same as the first comment (although it was pre-existing).
if (!xpath) { virReportOOMError(); goto cleanup; @@ -7087,25 +7114,17 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) VIR_FREE(xpath); if (tmp) tls_port = 0; - - if (vshCommandOptBool(cmd, "include-password")) { - /* Create our XPATH lookup for the SPICE password */ - virAsprintf(&xpath, "string(/domain/devices/graphics" - "[@type='%s']/@passwd)", scheme[iter]); - if (!xpath) { - virReportOOMError(); - goto cleanup; - } - - /* Attempt to get the SPICE password */ - passwd = virXPathString(xpath, ctxt); - VIR_FREE(xpath); - } }
/* Build up the full URI, starting with the scheme */ virBufferAsprintf(&buf, "%s://", scheme[iter]);
+ /* There is no user, so just append password if there's any */ + if (passwd) { + virBufferAsprintf(&buf, ":%s@", passwd);
Doesn't this break something that was working previously? I'm not using this but the original way was to append "?password=adsgf".
+ VIR_FREE(passwd);
Move this free to the cleanup section.
+ } + /* Then host name or IP */ if (!listen_addr || STREQ((const char *)listen_addr, "0.0.0.0")) virBufferAddLit(&buf, "localhost"); @@ -7115,20 +7134,11 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) VIR_FREE(listen_addr);
/* Add the port */ - if (STREQ(scheme[iter], "spice")) - virBufferAsprintf(&buf, "?port=%d", port); - else - virBufferAsprintf(&buf, ":%d", port); + virBufferAsprintf(&buf, ":%d", port);
/* TLS Port */ if (tls_port) - virBufferAsprintf(&buf, "&tls-port=%d", tls_port); - - /* Password */ - if (passwd) { - virBufferAsprintf(&buf, "&password=%s", passwd); - VIR_FREE(passwd); - } + virBufferAsprintf(&buf, "?tls-port=%d", tls_port);
/* Ensure we can print our URI */ if (virBufferError(&buf)) {
I'm not sure about the change of the password parameter. Could you back that up somehow? Peter

On 11/22/2012 02:10 PM, Peter Krempa wrote:
On 11/22/12 11:34, Martin Kletzander wrote:
The 'virsh domdisplay' command is able to display the password configured for spice, but it was missing for vnc type graphics. Also, there were some inconsistencies that are cleaned now. --- [...] + } + /* Then host name or IP */ if (!listen_addr || STREQ((const char *)listen_addr, "0.0.0.0")) virBufferAddLit(&buf, "localhost"); @@ -7115,20 +7134,11 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) VIR_FREE(listen_addr);
/* Add the port */ - if (STREQ(scheme[iter], "spice")) - virBufferAsprintf(&buf, "?port=%d", port); - else - virBufferAsprintf(&buf, ":%d", port); + virBufferAsprintf(&buf, ":%d", port);
/* TLS Port */ if (tls_port) - virBufferAsprintf(&buf, "&tls-port=%d", tls_port); - - /* Password */ - if (passwd) { - virBufferAsprintf(&buf, "&password=%s", passwd); - VIR_FREE(passwd); - } + virBufferAsprintf(&buf, "?tls-port=%d", tls_port);
/* Ensure we can print our URI */ if (virBufferError(&buf)) {
I'm not sure about the change of the password parameter. Could you back that up somehow?
Unfortunately I cannot. spicy is unable to parse the new version correctly, but I believe that's a bug since there is a common knowledge where to put the password. I cooked up a win/win version with the spice password being printed out the old way and vnc the new (standard) way, so hopefully everyone could be satisfied, but that seems *very* inconsistent to me. But since I also shrunk the code a bit more and fixed one more thing there, I'll send it and let's hope we'll come to some conclusion then. Martin
participants (2)
-
Martin Kletzander
-
Peter Krempa