Logoj0ke.net Open Build Service > Projects > virtualization > libvirt > auth-callback.patch
Sign Up | Log In

File auth-callback.patch of Package libvirt (Revision d67dfd6895f8b3523cb931e8f7ba4b56)

Currently displaying revision d67dfd6895f8b3523cb931e8f7ba4b56, show latest

x
 
1
diff -ru a/src/remote_internal.c b/src/remote_internal.c
2
--- a/src/remote_internal.c 2007-12-17 14:51:09.000000000 -0700
3
+++ b/src/remote_internal.c 2008-04-09 15:56:59.000000000 -0600
4
@@ -3054,8 +3054,12 @@
5
     if ((remoteAddr = addrToString(&sa, salen)) == NULL)
6
         goto cleanup;
7
 
8
-    if ((saslcb = remoteAuthMakeCallbacks(auth->credtype, auth->ncredtype)) == NULL)
9
-        goto cleanup;
10
+    if (auth) {
11
+        if ((saslcb = remoteAuthMakeCallbacks(auth->credtype, auth->ncredtype)) == NULL)
12
+            goto cleanup;
13
+    } else {
14
+        saslcb = NULL;
15
+    }
16
 
17
     /* Setup a handle for being a client */
18
     err = sasl_client_new("libvirt",
19
@@ -3168,15 +3172,21 @@
20
             goto cleanup;
21
         }
22
         /* Run the authentication callback */
23
-        if ((*(auth->cb))(cred, ncred, auth->cbdata) < 0) {
24
+        if (auth && auth->cb) {
25
+            if ((*(auth->cb))(cred, ncred, auth->cbdata) < 0) {
26
+                __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
27
+                                 VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
28
+                                 "Failed to collect auth credentials");
29
+                goto cleanup;
30
+            }
31
+            remoteAuthFillInteract(cred, interact);
32
+            goto restart;
33
+        } else {
34
             __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
35
                              VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
36
-                             "Failed to collect auth credentials");
37
+                             "No authentication callback available");
38
             goto cleanup;
39
-            return -1;
40
         }
41
-        remoteAuthFillInteract(cred, interact);
42
-        goto restart;
43
     }
44
     free(iret.mechlist);
45
 
46
@@ -3240,15 +3250,22 @@
47
                 return -1;
48
             }
49
             /* Run the authentication callback */
50
-            if ((*(auth->cb))(cred, ncred, auth->cbdata) < 0) {
51
+            if (auth && auth->cb) {
52
+                if ((*(auth->cb))(cred, ncred, auth->cbdata) < 0) {
53
+                    __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
54
+                                     VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
55
+                                     "Failed to collect auth credentials");
56
+                    goto cleanup;
57
+                    return -1;
58
+                }
59
+                remoteAuthFillInteract(cred, interact);
60
+                goto restep;
61
+            } else {
62
                 __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
63
                                  VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
64
-                                 "Failed to collect auth credentials");
65
+                                 "No authentication callback available");
66
                 goto cleanup;
67
-                return -1;
68
             }
69
-            remoteAuthFillInteract(cred, interact);
70
-            goto restep;
71
         }
72
 
73
         if (serverin) {
74
@@ -3319,7 +3336,8 @@
75
     if (remoteAddr) free(remoteAddr);
76
     if (serverin) free(serverin);
77
 
78
-    free(saslcb);
79
+    if (saslcb)
80
+        free(saslcb);
81
     remoteAuthFreeCredentials(cred, ncred);
82
     if (ret != 0 && saslconn)
83
         sasl_dispose(&saslconn);
84
@@ -3347,24 +3365,26 @@
85
     };
86
     remoteDebug(priv, "Client initialize PolicyKit authentication");
87
 
88
-    for (i = 0 ; i < auth->ncredtype ; i++) {
89
-        if (auth->credtype[i] == VIR_CRED_EXTERNAL)
90
-            allowcb = 1;
91
-    }
92
+    if (auth && auth->cb) {
93
+        /* Check if the neccessary credential type for PolicyKit is supported */
94
+        for (i = 0 ; i < auth->ncredtype ; i++) {
95
+            if (auth->credtype[i] == VIR_CRED_EXTERNAL)
96
+                allowcb = 1;
97
+        }
98
 
99
-    /* Run the authentication callback */
100
-    if (allowcb) {
101
-        if (auth && auth->cb &&
102
-            (*(auth->cb))(&cred, 1, auth->cbdata) < 0) {
103
-            __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
104
-                             VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
105
-                             "Failed to collect auth credentials");
106
-            return -1;
107
+        if (allowcb) {
108
+            /* Run the authentication callback */
109
+            if ((*(auth->cb))(&cred, 1, auth->cbdata) < 0) {
110
+                __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
111
+                                 VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
112
+                                 "Failed to collect auth credentials");
113
+                return -1;
114
+            }
115
         } else {
116
-            remoteDebug(priv, "No auth callback provided for PolicyKit");
117
+            remoteDebug(priv, "Client auth callback does not support PolicyKit");
118
         }
119
     } else {
120
-        remoteDebug(priv, "Client auth callback does not support PolicyKit");
121
+        remoteDebug(priv, "No auth callback provided");
122
     }
123
 
124
     memset (&ret, 0, sizeof ret);
125