[gnome-control-center] printers: Authenticate Samba servers only when enabled



commit 22f508a7e1e65e0620c518b1186f9e7381071f1d
Author: Marek Kasik <mkasik redhat com>
Date:   Mon Sep 2 16:31:24 2013 +0200

    printers: Authenticate Samba servers only when enabled
    
    Add parameter which enables showing of authentication dialog
    for Samba servers which need authentication.
    Add samba server to the internal list of found devices if it needs
    authentication and the authentication is disabled.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=698532

 panels/printers/pp-new-printer-dialog.c |    3 ++-
 panels/printers/pp-samba.c              |   20 +++++++++++++++++---
 panels/printers/pp-samba.h              |    1 +
 panels/printers/pp-utils.h              |   26 ++++++++++++++------------
 4 files changed, 34 insertions(+), 16 deletions(-)
---
diff --git a/panels/printers/pp-new-printer-dialog.c b/panels/printers/pp-new-printer-dialog.c
index e553f46..e183ff4 100644
--- a/panels/printers/pp-new-printer-dialog.c
+++ b/panels/printers/pp-new-printer-dialog.c
@@ -1371,6 +1371,7 @@ search_address_cb (GtkEntry *entry,
                                               dialog);
 
               pp_samba_get_devices_async (samba_host,
+                                          TRUE,
                                           priv->cancellable,
                                           get_samba_host_devices_cb,
                                           dialog);
@@ -1580,7 +1581,7 @@ populate_devices_list (PpNewPrinterDialog *dialog)
   update_spinner_state (dialog);
 
   samba = pp_samba_new (GTK_WINDOW (priv->dialog), NULL);
-  pp_samba_get_devices_async (samba, priv->cancellable, get_samba_devices_cb, dialog);
+  pp_samba_get_devices_async (samba, FALSE, priv->cancellable, get_samba_devices_cb, dialog);
 }
 
 static void
diff --git a/panels/printers/pp-samba.c b/panels/printers/pp-samba.c
index 93f751a..e876a53 100644
--- a/panels/printers/pp-samba.c
+++ b/panels/printers/pp-samba.c
@@ -188,6 +188,7 @@ typedef struct
   PpDevicesList *devices;
   GMainContext  *context;
   gboolean       waiting;
+  gboolean       auth_if_needed;
   GtkWindow     *parent;
   SMBAuthInfo   *auth_info;
   gboolean       hostname_set;
@@ -348,9 +349,20 @@ list_dir (SMBCCTX      *smb_context,
       dir = smbclient_opendir (smb_context, dirname);
       if (!dir && errno == EACCES)
         {
-          smbc_setFunctionAuthDataWithContext (smb_context, auth_fn);
-          dir = smbclient_opendir (smb_context, dirname);
-          smbc_setFunctionAuthDataWithContext (smb_context, anonymous_auth_fn);
+          if (data->auth_if_needed)
+            {
+              smbc_setFunctionAuthDataWithContext (smb_context, auth_fn);
+              dir = smbclient_opendir (smb_context, dirname);
+              smbc_setFunctionAuthDataWithContext (smb_context, anonymous_auth_fn);
+            }
+          else
+            {
+              device = g_new0 (PpPrintDevice, 1);
+              device->host_name = g_str_has_prefix (dirname, "smb://") ? g_strdup (dirname + 6) : g_strdup 
(dirname);
+              device->is_authenticated_server = TRUE;
+
+              data->devices->devices = g_list_append (data->devices->devices, device);
+            }
         }
 
       while (dir && (dirent = smbclient_readdir (smb_context, dir)))
@@ -464,6 +476,7 @@ _pp_samba_get_devices_thread (GSimpleAsyncResult *res,
 
 void
 pp_samba_get_devices_async (PpSamba             *samba,
+                            gboolean             auth_if_needed,
                             GCancellable        *cancellable,
                             GAsyncReadyCallback  callback,
                             gpointer             user_data)
@@ -478,6 +491,7 @@ pp_samba_get_devices_async (PpSamba             *samba,
   data->context = g_main_context_default ();
   data->hostname_set = priv->hostname != NULL;
   data->parent = g_object_ref (priv->parent);
+  data->auth_if_needed = auth_if_needed;
 
   g_simple_async_result_set_check_cancellable (res, cancellable);
   g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify) smb_data_free);
diff --git a/panels/printers/pp-samba.h b/panels/printers/pp-samba.h
index 64d505f..1f6372e 100644
--- a/panels/printers/pp-samba.h
+++ b/panels/printers/pp-samba.h
@@ -54,6 +54,7 @@ PpSamba       *pp_samba_new                (GtkWindow           *parent,
                                             const gchar         *hostname);
 
 void           pp_samba_get_devices_async  (PpSamba             *samba,
+                                            gboolean             auth_if_needed,
                                             GCancellable        *cancellable,
                                             GAsyncReadyCallback  callback,
                                             gpointer             user_data);
diff --git a/panels/printers/pp-utils.h b/panels/printers/pp-utils.h
index 2514f76..4a62c05 100644
--- a/panels/printers/pp-utils.h
+++ b/panels/printers/pp-utils.h
@@ -273,18 +273,20 @@ void job_set_hold_until_async (gint          job_id,
                                GCancellable *cancellable,
                                JSHUCallback  callback,
                                gpointer      user_data);
-typedef struct{
-  gchar *device_class;
-  gchar *device_id;
-  gchar *device_info;
-  gchar *device_make_and_model;
-  gchar *device_uri;
-  gchar *device_location;
-  gchar *device_name;
-  gchar *device_ppd;
-  gchar *host_name;
-  gint   host_port;
-  gint   acquisition_method;
+typedef struct
+{
+  gboolean  is_authenticated_server;
+  gchar    *device_class;
+  gchar    *device_id;
+  gchar    *device_info;
+  gchar    *device_make_and_model;
+  gchar    *device_uri;
+  gchar    *device_location;
+  gchar    *device_name;
+  gchar    *device_ppd;
+  gchar    *host_name;
+  gint      host_port;
+  gint      acquisition_method;
 } PpPrintDevice;
 
 void        pp_print_device_free (PpPrintDevice *device);


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