[libvirt] [PATCH 1/2] util: Add possibility to call virAuthGetPassword without conn object

Peter Krempa pkrempa at redhat.com
Tue Nov 27 14:39:16 UTC 2012


To make this function callable from code that doesn't have the conn
object, call the conn-dependant code only if conn was provided.
---
 src/util/virauth.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/util/virauth.c b/src/util/virauth.c
index 6d9935d..738b3c5 100644
--- a/src/util/virauth.c
+++ b/src/util/virauth.c
@@ -205,7 +205,8 @@ virAuthGetUsername(virConnectPtr conn,
 }


-
+/* if this function is called with conn == NULL, the code requesting
+ * the password from the config file is skipped */
 char *
 virAuthGetPassword(virConnectPtr conn,
                    virConnectAuthPtr auth,
@@ -218,10 +219,12 @@ virAuthGetPassword(virConnectPtr conn,
     char *prompt;
     char *ret = NULL;

-    if (virAuthGetCredential(conn, servicename, "password", &ret) < 0)
-        return NULL;
-    if (ret != NULL)
-        return ret;
+    if (conn) {
+        if (virAuthGetCredential(conn, servicename, "password", &ret) < 0)
+            return NULL;
+        if (ret != NULL)
+            return ret;
+    }

     memset(&cred, 0, sizeof(virConnectCredential));

-- 
1.8.0




More information about the libvir-list mailing list