]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
esx: Move username and password helper functions to authhelper.c
authorMatthias Bolte <matthias.bolte@googlemail.com>
Sun, 14 Mar 2010 19:50:14 +0000 (20:50 +0100)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Tue, 16 Mar 2010 19:15:32 +0000 (20:15 +0100)
po/POTFILES.in
src/Makefile.am
src/esx/esx_driver.c
src/esx/esx_util.c
src/esx/esx_util.h
src/util/authhelper.c [new file with mode: 0644]
src/util/authhelper.h [new file with mode: 0644]

index 18455728cef425b815241ec4b860eb76d119ae2a..3f9fc391cb339e44f230fafd3c7044cba6dc7e6f 100644 (file)
@@ -55,6 +55,7 @@ src/storage/storage_driver.c
 src/test/test_driver.c
 src/uml/uml_conf.c
 src/uml/uml_driver.c
+src/util/authhelper.c
 src/util/bridge.c
 src/util/conf.c
 src/util/hostusb.c
index c43797a7d1e741733e126bb511e688ffef4dacc0..3156715b2511e39590d7206434c80ef188e89a64 100644 (file)
@@ -45,6 +45,7 @@ augeastest_DATA =
 # These files are not related to driver APIs. Simply generic
 # helper APIs for various purposes
 UTIL_SOURCES =                                                 \
+               util/authhelper.c util/authhelper.h             \
                util/bridge.c util/bridge.h                     \
                util/buf.c util/buf.h                           \
                util/conf.c util/conf.h                         \
index c47af1ceda14ff20a5aff1459a4662c988f3c256..ed2cbf738d172c62ee57f560c5c5ce1d592041b3 100644 (file)
@@ -29,6 +29,7 @@
 #include "internal.h"
 #include "virterror_internal.h"
 #include "domain_conf.h"
+#include "authhelper.h"
 #include "util.h"
 #include "memory.h"
 #include "logging.h"
@@ -354,7 +355,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
             goto failure;
         }
     } else {
-        username = esxUtil_RequestUsername(auth, "root", conn->uri->server);
+        username = virRequestUsername(auth, "root", conn->uri->server);
 
         if (username == NULL) {
             ESX_ERROR(VIR_ERR_AUTH_FAILED, "Username request failed");
@@ -366,7 +367,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
         goto failure;
     }
 
-    password = esxUtil_RequestPassword(auth, username, conn->uri->server);
+    password = virRequestPassword(auth, username, conn->uri->server);
 
     if (password == NULL) {
         ESX_ERROR(VIR_ERR_AUTH_FAILED, "Password request failed");
@@ -491,14 +492,14 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
             goto failure;
         }
 
-        username = esxUtil_RequestUsername(auth, "administrator", vCenter);
+        username = virRequestUsername(auth, "administrator", vCenter);
 
         if (username == NULL) {
             ESX_ERROR(VIR_ERR_AUTH_FAILED, "Username request failed");
             goto failure;
         }
 
-        password = esxUtil_RequestPassword(auth, username, vCenter);
+        password = virRequestPassword(auth, username, vCenter);
 
         if (password == NULL) {
             ESX_ERROR(VIR_ERR_AUTH_FAILED, "Password request failed");
index dcbd86c25c6b277752692cf230c5def30d872cc5..3cbd2b1d75241860d70043d440f242e1e0bf53e1 100644 (file)
 
 
 
-char *
-esxUtil_RequestUsername(virConnectAuthPtr auth, const char *defaultUsername,
-                        const char *hostname)
-{
-    unsigned int ncred;
-    virConnectCredential cred;
-    char *prompt = NULL;
-
-    memset(&cred, 0, sizeof(virConnectCredential));
-
-    if (virAsprintf(&prompt, "Enter username for %s [%s]", hostname,
-                    defaultUsername) < 0) {
-        return NULL;
-    }
-
-    for (ncred = 0; ncred < auth->ncredtype; ncred++) {
-        if (auth->credtype[ncred] != VIR_CRED_AUTHNAME) {
-            continue;
-        }
-
-        cred.type = VIR_CRED_AUTHNAME;
-        cred.prompt = prompt;
-        cred.challenge = hostname;
-        cred.defresult = defaultUsername;
-        cred.result = NULL;
-        cred.resultlen = 0;
-
-        if ((*(auth->cb))(&cred, 1, auth->cbdata) < 0) {
-            VIR_FREE(cred.result);
-        }
-
-        break;
-    }
-
-    VIR_FREE(prompt);
-
-    return cred.result;
-}
-
-
-
-char *
-esxUtil_RequestPassword(virConnectAuthPtr auth, const char *username,
-                        const char *hostname)
-{
-    unsigned int ncred;
-    virConnectCredential cred;
-    char *prompt;
-
-    memset(&cred, 0, sizeof(virConnectCredential));
-
-    if (virAsprintf(&prompt, "Enter %s password for %s", username,
-                    hostname) < 0) {
-        return NULL;
-    }
-
-    for (ncred = 0; ncred < auth->ncredtype; ncred++) {
-        if (auth->credtype[ncred] != VIR_CRED_PASSPHRASE &&
-            auth->credtype[ncred] != VIR_CRED_NOECHOPROMPT) {
-            continue;
-        }
-
-        cred.type = auth->credtype[ncred];
-        cred.prompt = prompt;
-        cred.challenge = hostname;
-        cred.defresult = NULL;
-        cred.result = NULL;
-        cred.resultlen = 0;
-
-        if ((*(auth->cb))(&cred, 1, auth->cbdata) < 0) {
-            VIR_FREE(cred.result);
-        }
-
-        break;
-    }
-
-    VIR_FREE(prompt);
-
-    return cred.result;
-}
-
-
-
 int
 esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter,
                    int *noVerify, int *autoAnswer)
index b5cb419d8c00c18af4b2973a1e19e1e0be1c083e..f4f971ca62c1f05d0f293339d8142aa95e38447f 100644 (file)
 # include "internal.h"
 # include "conf.h"
 
-char *esxUtil_RequestUsername(virConnectAuthPtr auth,
-                              const char *defaultUsername,
-                              const char *hostname);
-
-char *esxUtil_RequestPassword(virConnectAuthPtr auth, const char *username,
-                              const char *hostname);
-
 int esxUtil_ParseQuery(xmlURIPtr uri, char **transport, char **vCenter,
                        int *noVerify, int *autoAnswer);
 
diff --git a/src/util/authhelper.c b/src/util/authhelper.c
new file mode 100644 (file)
index 0000000..9398cb3
--- /dev/null
@@ -0,0 +1,115 @@
+
+/*
+ * authhelper.c: authentication related utility functions
+ *
+ * Copyright (C) 2010 Matthias Bolte <matthias.bolte@googlemail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ */
+
+#include <config.h>
+
+#include "authhelper.h"
+#include "util.h"
+#include "memory.h"
+
+
+char *
+virRequestUsername(virConnectAuthPtr auth, const char *defaultUsername,
+                   const char *hostname)
+{
+    unsigned int ncred;
+    virConnectCredential cred;
+    char *prompt;
+
+    memset(&cred, 0, sizeof (virConnectCredential));
+
+    if (defaultUsername != NULL) {
+        if (virAsprintf(&prompt, _("Enter username for %s [%s]"), hostname,
+                        defaultUsername) < 0) {
+            return NULL;
+        }
+    } else {
+        if (virAsprintf(&prompt, _("Enter username for %s"), hostname) < 0) {
+            return NULL;
+        }
+    }
+
+    for (ncred = 0; ncred < auth->ncredtype; ncred++) {
+        if (auth->credtype[ncred] != VIR_CRED_AUTHNAME) {
+            continue;
+        }
+
+        cred.type = VIR_CRED_AUTHNAME;
+        cred.prompt = prompt;
+        cred.challenge = hostname;
+        cred.defresult = defaultUsername;
+        cred.result = NULL;
+        cred.resultlen = 0;
+
+        if ((*(auth->cb))(&cred, 1, auth->cbdata) < 0) {
+            VIR_FREE(cred.result);
+        }
+
+        break;
+    }
+
+    VIR_FREE(prompt);
+
+    return cred.result;
+}
+
+
+
+char *
+virRequestPassword(virConnectAuthPtr auth, const char *username,
+                   const char *hostname)
+{
+    unsigned int ncred;
+    virConnectCredential cred;
+    char *prompt;
+
+    memset(&cred, 0, sizeof (virConnectCredential));
+
+    if (virAsprintf(&prompt, _("Enter %s's password for %s"), username,
+                    hostname) < 0) {
+        return NULL;
+    }
+
+    for (ncred = 0; ncred < auth->ncredtype; ncred++) {
+        if (auth->credtype[ncred] != VIR_CRED_PASSPHRASE &&
+            auth->credtype[ncred] != VIR_CRED_NOECHOPROMPT) {
+            continue;
+        }
+
+        cred.type = auth->credtype[ncred];
+        cred.prompt = prompt;
+        cred.challenge = hostname;
+        cred.defresult = NULL;
+        cred.result = NULL;
+        cred.resultlen = 0;
+
+        if ((*(auth->cb))(&cred, 1, auth->cbdata) < 0) {
+            VIR_FREE(cred.result);
+        }
+
+        break;
+    }
+
+    VIR_FREE(prompt);
+
+    return cred.result;
+}
diff --git a/src/util/authhelper.h b/src/util/authhelper.h
new file mode 100644 (file)
index 0000000..ca45d16
--- /dev/null
@@ -0,0 +1,33 @@
+
+/*
+ * authhelper.h: authentication related utility functions
+ *
+ * Copyright (C) 2010 Matthias Bolte <matthias.bolte@googlemail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ */
+
+#ifndef __VIR_AUTHHELPER_H__
+# define __VIR_AUTHHELPER_H__
+
+# include "internal.h"
+
+char *virRequestUsername(virConnectAuthPtr auth, const char *defaultUsername,
+                         const char *hostname);
+char *virRequestPassword(virConnectAuthPtr auth, const char *username,
+                         const char *hostname);
+
+#endif /* __VIR_AUTHHELPER_H__ */