[PATCH] CUPS Authentication support



The attached patch adds authentication support in the GTK+ CUPS backend.
For now it only works with authentication mechanisms that don't require
password prompting (in other words, GSSAPI). 

Successfully tested against CUPS using GSSAPI.

Cheers,

Jelmer
-- 
Jelmer Vernooij <jelmer samba org> - http://samba.org/~jelmer/
Jabber: jelmer jabber fsfe org
=== modified file 'modules/printbackends/cups/gtkcupsutils.c'
--- modules/printbackends/cups/gtkcupsutils.c	2008-09-17 21:07:10 +0000
+++ modules/printbackends/cups/gtkcupsutils.c	2008-09-25 00:22:33 +0000
@@ -810,17 +810,30 @@
     }
   else if (http_status == HTTP_UNAUTHORIZED)
     {
-      /* TODO: callout for auth */
-      g_warning ("NOT IMPLEMENTED: We need to prompt for authorization");
+      int auth_result;
+
+      auth_result = cupsDoAuthentication (request->http, "POST", 
+                                          request->resource);
+      if (auth_result == 0)
+        {
+          request->state = GTK_CUPS_POST_CONNECT;
+
+          /* Reconnect... */
+          httpReconnect (request->http);
+
+          request->attempts++;
+          goto again;
+        }
+
       request->state = GTK_CUPS_POST_DONE;
       request->poll_state = GTK_CUPS_HTTP_IDLE;
       
-      /* TODO: create a not implemented error code */
       gtk_cups_result_set_error (request->result, 
                                  GTK_CUPS_ERROR_GENERAL,
                                  0,
                                  0,
-                                 "Can't prompt for authorization");
+                                 "Authentication failed");
+    httpFlush (request->http); 
       return;
     }
   else if (http_status == HTTP_ERROR)
@@ -985,7 +998,7 @@
         {
           request->state = GTK_CUPS_GET_DONE;
           request->poll_state = GTK_CUPS_HTTP_IDLE;
-	 
+ 
           /* TODO: should add a status or error code for failed GET */ 
           gtk_cups_result_set_error (request->result, 
                                      GTK_CUPS_ERROR_GENERAL,
@@ -1024,17 +1037,30 @@
     }
   else if (http_status == HTTP_UNAUTHORIZED)
     {
-      /* TODO: callout for auth */
-      g_warning ("NOT IMPLEMENTED: We need to prompt for authorization in a non blocking manner");
-      request->state = GTK_CUPS_GET_DONE;
+      int auth_result;
+
+      auth_result = cupsDoAuthentication (request->http, "POST", 
+                                          request->resource);
+      if (auth_result == 0)
+        {
+          request->state = GTK_CUPS_POST_CONNECT;
+
+          /* Reconnect... */
+          httpReconnect (request->http);
+
+          request->attempts++;
+          goto again;
+        }
+
+      request->state = GTK_CUPS_POST_DONE;
       request->poll_state = GTK_CUPS_HTTP_IDLE;
-
-      /* TODO: should add a status or error code for not implemented */ 
+      
       gtk_cups_result_set_error (request->result, 
                                  GTK_CUPS_ERROR_GENERAL,
                                  0,
                                  0,
-                                 "Can't prompt for authorization");
+                                 "Authentication failed");
+    httpFlush (request->http); 
       return;
     }
   else if (http_status == HTTP_UPGRADE_REQUIRED)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]