r5987: Add credentials callback for gtk+. The gtk+ apps now no longer
authorJelmer Vernooij <jelmer@samba.org>
Wed, 23 Mar 2005 01:02:29 +0000 (01:02 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:11:12 +0000 (13:11 -0500)
ask for a password when kerberos is being used.

source/gtk/common/credentials.c [new file with mode: 0644]
source/gtk/common/gtk-smb.c
source/gtk/common/gtk-smb.h
source/gtk/common/select.c
source/gtk/common/select.h
source/gtk/config.mk

diff --git a/source/gtk/common/credentials.c b/source/gtk/common/credentials.c
new file mode 100644 (file)
index 0000000..dce7722
--- /dev/null
@@ -0,0 +1,95 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   Copyright (C) Jelmer Vernooij 2005
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program 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 General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "gtk/common/gtk-smb.h"
+
+static const char *gtk_get_userpassword(struct cli_credentials *credentials)
+{
+       char *prompt;
+       const char *ret;
+       GtkWidget *dialog;
+       GtkWidget *dialog_vbox1;
+       GtkWidget *hbox;
+       GtkWidget *label;
+       GtkWidget *entry_password;
+       GtkWidget *dialog_action_area1;
+       GtkWidget *cancelbutton1;
+       GtkWidget *okbutton1;
+
+       dialog = gtk_dialog_new ();
+       gtk_window_set_title (GTK_WINDOW (dialog), "Enter Password");
+       gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+       gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
+
+       dialog_vbox1 = GTK_DIALOG (dialog)->vbox;
+
+       hbox = gtk_hbox_new (FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (dialog_vbox1), hbox, TRUE, TRUE, 0);
+
+       prompt = talloc_asprintf(NULL, "Password for [%s\\%s]:", 
+                                                        cli_credentials_get_domain(credentials),
+                                                        cli_credentials_get_username(credentials));
+
+       label = gtk_label_new (prompt);
+
+       gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+       entry_password = gtk_entry_new ();
+       gtk_box_pack_start (GTK_BOX (hbox), entry_password, TRUE, TRUE, 0);
+       gtk_entry_set_visibility (GTK_ENTRY (entry_password), FALSE);
+       gtk_entry_set_activates_default (GTK_ENTRY (entry_password), TRUE);
+
+       dialog_action_area1 = GTK_DIALOG (dialog)->action_area;
+       gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END);
+
+       cancelbutton1 = gtk_button_new_from_stock ("gtk-cancel");
+       gtk_dialog_add_action_widget (GTK_DIALOG (dialog), cancelbutton1, GTK_RESPONSE_CANCEL);
+       GTK_WIDGET_SET_FLAGS (cancelbutton1, GTK_CAN_DEFAULT);
+
+       okbutton1 = gtk_button_new_from_stock ("gtk-ok");
+       gtk_dialog_add_action_widget (GTK_DIALOG (dialog), okbutton1, GTK_RESPONSE_OK);
+       GTK_WIDGET_SET_FLAGS (okbutton1, GTK_CAN_DEFAULT);
+
+       gtk_widget_show_all (dialog);
+
+    switch (gtk_dialog_run (GTK_DIALOG (dialog))) {
+       case GTK_RESPONSE_OK:
+               ret = talloc_strdup(credentials, gtk_entry_get_text(GTK_ENTRY(entry_password)));
+               break;
+       default:
+               ret = NULL;
+               break;
+       }
+
+       gtk_widget_destroy (dialog);
+
+       talloc_free(prompt);
+       
+       return ret;
+}
+
+void cli_credentials_set_gtk_callbacks(struct cli_credentials *cred)
+{
+       if (cred->password_obtained <= CRED_CALLBACK) {
+               cred->password_cb = gtk_get_userpassword;
+               cred->password_obtained = CRED_CALLBACK;
+       }
+}
index a84f9f639d3803de825340a446f61852cc948c0e..f4458442f0fa0d7657242f625c88297a930f240d 100644 (file)
@@ -20,8 +20,8 @@
 */
 
 #include "includes.h"
-#include "gtk/common/select.h"
 #include "gtk/common/gtk-smb.h"
+#include "gtk/common/select.h"
 
 void gtk_show_werror(GtkWidget *win, const char *message, WERROR err) 
 {
@@ -58,11 +58,6 @@ static void on_browse_activate  (GtkButton     *button,  gpointer         user_d
        gtk_widget_destroy(GTK_WIDGET(shd));
 }
 
-static void on_krb5_toggled(GtkToggleButton *togglebutton, GtkRpcBindingDialog *d)
-{
-       gtk_widget_set_sensitive(d->entry_password, !gtk_toggle_button_get_active(togglebutton));
-}
-
 static void on_ncalrpc_toggled(GtkToggleButton *tb, GtkRpcBindingDialog *d)
 {
        gtk_widget_set_sensitive(d->frame_host, !gtk_toggle_button_get_active(tb));
@@ -84,7 +79,6 @@ static void gtk_rpc_binding_dialog_init (GtkRpcBindingDialog *gtk_rpc_binding_di
        GtkWidget *table1;
        GtkWidget *lbl_username;
        GtkWidget *lbl_userdomain;
-       GtkWidget *lbl_password;
        GtkWidget *btn_browse;
        GtkWidget *label9;
        GtkWidget *lbl_credentials;
@@ -98,6 +92,7 @@ static void gtk_rpc_binding_dialog_init (GtkRpcBindingDialog *gtk_rpc_binding_di
        gtk_rpc_binding_dialog->credentials = cli_credentials_init(gtk_rpc_binding_dialog->mem_ctx);
 
        cli_credentials_guess(gtk_rpc_binding_dialog->credentials);
+       cli_credentials_set_gtk_callbacks(gtk_rpc_binding_dialog->credentials);
        
        gtk_window_set_title (GTK_WINDOW (gtk_rpc_binding_dialog), "Connect");
 
@@ -192,12 +187,6 @@ static void gtk_rpc_binding_dialog_init (GtkRpcBindingDialog *gtk_rpc_binding_di
                                          (GtkAttachOptions) (0), 0, 0);
        gtk_misc_set_alignment (GTK_MISC (lbl_userdomain), 0, 0.5);
 
-       lbl_password = gtk_label_new ("Password:");
-       gtk_table_attach (GTK_TABLE (table1), lbl_password, 0,1, 2,3,
-                                         (GtkAttachOptions) (GTK_FILL),
-                                         (GtkAttachOptions) (0), 0, 0);
-       gtk_misc_set_alignment (GTK_MISC (lbl_password), 0, 0.5);
-
        label9 = gtk_label_new ("");
        gtk_table_attach (GTK_TABLE (table1), label9, 0,1, 3,4,
                                          (GtkAttachOptions) (GTK_FILL),
@@ -220,24 +209,11 @@ static void gtk_rpc_binding_dialog_init (GtkRpcBindingDialog *gtk_rpc_binding_di
        gtk_entry_set_text(GTK_ENTRY(gtk_rpc_binding_dialog->entry_userdomain), 
                                           cli_credentials_get_domain(gtk_rpc_binding_dialog->credentials));
 
-       gtk_rpc_binding_dialog->entry_password = gtk_entry_new ();
-       gtk_entry_set_visibility (GTK_ENTRY (gtk_rpc_binding_dialog->entry_password), FALSE);
-       gtk_table_attach (GTK_TABLE (table1), gtk_rpc_binding_dialog->entry_password, 1,2, 2,3,
-                                         (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
-                                         (GtkAttachOptions) (0), 0, 0);
-
-       gtk_entry_set_text(GTK_ENTRY(gtk_rpc_binding_dialog->entry_password), 
-                                          cli_credentials_get_password(gtk_rpc_binding_dialog->credentials));
-
        gtk_rpc_binding_dialog->krb5_chk_button = gtk_check_button_new_with_mnemonic ("_Use kerberos");
        gtk_table_attach (GTK_TABLE (table1), gtk_rpc_binding_dialog->krb5_chk_button, 1,2, 3,4,
                                          (GtkAttachOptions) (GTK_FILL),
                                          (GtkAttachOptions) (0), 0, 0);
 
-       g_signal_connect ((gpointer) gtk_rpc_binding_dialog->krb5_chk_button, "toggled",
-                                         G_CALLBACK (on_krb5_toggled),
-                                         gtk_rpc_binding_dialog);
-
        /* Poor man's autodetection */
        if(getenv("KRB5CCNAME")) {
                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(gtk_rpc_binding_dialog->krb5_chk_button), TRUE);
@@ -296,7 +272,7 @@ GType gtk_rpc_binding_dialog_get_type (void)
   return mytype;
 }
 
-GtkWidget *gtk_rpc_binding_dialog_new (BOOL nocredentials, struct sam_pipe *sam_pipe)
+GtkWidget *gtk_rpc_binding_dialog_new (BOOL nocredentials, struct dcerpc_pipe *sam_pipe)
 {
        GtkRpcBindingDialog *d = GTK_RPC_BINDING_DIALOG ( g_object_new (gtk_rpc_binding_dialog_get_type (), NULL));
        if (nocredentials) {
@@ -309,7 +285,6 @@ GtkWidget *gtk_rpc_binding_dialog_new (BOOL nocredentials, struct sam_pipe *sam_
 struct cli_credentials *gtk_rpc_binding_dialog_get_credentials(GtkRpcBindingDialog *d)
 {
        cli_credentials_set_username(d->credentials, gtk_entry_get_text(GTK_ENTRY(d->entry_username)), CRED_SPECIFIED);
-       cli_credentials_set_password(d->credentials, gtk_entry_get_text(GTK_ENTRY(d->entry_password)), CRED_SPECIFIED);
        cli_credentials_set_domain(d->credentials, gtk_entry_get_text(GTK_ENTRY(d->entry_userdomain)), CRED_SPECIFIED);
        
        return d->credentials;
index 0a7bbcba0080c23259f7d6552ef1a6adf5511b95..2ff0a3be0cf12875e856c189edd9dde9a51c9aad 100644 (file)
 #ifndef __GTK_SMB_H__
 #define __GTK_SMB_H__
 
+
 #ifdef HAVE_GTK
 
+#define GTK_DISABLE_DEPRECATED
 #include <gtk/gtk.h>
 
 typedef struct _GtkRpcBindingDialog GtkRpcBindingDialog;
@@ -44,7 +46,7 @@ struct _GtkRpcBindingDialog
        GtkWidget *krb5_chk_button;
        GtkWidget *frame_credentials;
        TALLOC_CTX *mem_ctx;
-       struct sam_pipe *sam_pipe;
+       struct dcerpc_pipe *sam_pipe;
        struct cli_credentials *credentials;
 };
 
@@ -64,22 +66,18 @@ struct _GtkRpcBindingDialogClass
 /* subsystem prototypes */
 GtkWidget *create_gtk_samba_about_dialog (const char *appname);
 void gtk_show_ntstatus(GtkWidget *win, const char *, NTSTATUS status);
-GtkWidget *gtk_rpc_binding_dialog_new (BOOL nocredentials, struct sam_pipe *sam_pipe);
+GtkWidget *gtk_rpc_binding_dialog_new (BOOL nocredentials, struct dcerpc_pipe *sam_pipe);
 GType gtk_rpc_binding_dialog_get_type (void);
 struct dcerpc_binding *gtk_rpc_binding_dialog_get_binding(GtkRpcBindingDialog *d, TALLOC_CTX *mem_ctx);
-GtkWidget *gtk_select_host_dialog_new (struct sam_pipe *sam_pipe, BOOL nocredentials);
-const char *gtk_select_host_dialog_get_host (GtkSelectHostDialog *d);
-GType gtk_select_host_dialog_get_type (void);
 void gtk_show_werror(GtkWidget *win, const char *, WERROR err);
 const char *gtk_rpc_binding_dialog_get_binding_string(GtkRpcBindingDialog *d, TALLOC_CTX *mem_ctx);
 struct cli_credentials *gtk_rpc_binding_dialog_get_credentials(GtkRpcBindingDialog *d);
 const char *gtk_rpc_binding_dialog_get_host(GtkRpcBindingDialog *d);
-GtkWidget *gtk_select_domain_dialog_new (struct dcerpc_pipe *sam_pipe);
-GType gtk_select_domain_dialog_get_type (void);
-struct policy_handle gtk_select_domain_dialog_get_handle(GtkSelectDomainDialog *d);
 
 int gtk_event_loop(void);
 struct event_context;
 struct event_context *gtk_event_context(void);
 
+void cli_credentials_set_gtk_callbacks(struct cli_credentials *creds);
+
 #endif
index 269a84022035f3e6fdca2eea9f9dbea6514b5487..2075806f96995f0ded8dd05cf289eb0b690c1023 100644 (file)
@@ -256,7 +256,7 @@ GType gtk_select_host_dialog_get_type (void)
        return mytype;
 }
                                                                                                                              
-GtkWidget *gtk_select_host_dialog_new (struct sam_pipe *sam_pipe, BOOL nocredentials)
+GtkWidget *gtk_select_host_dialog_new (struct dcerpc_pipe *sam_pipe, BOOL nocredentials)
 {
         return GTK_WIDGET ( g_object_new (gtk_select_host_dialog_get_type (), NULL ));
 }
index 336359c322051387bb4b95c702ff35e569496309..4cbeb09b0d36214f65ab1677b46fece111172386 100644 (file)
@@ -25,7 +25,6 @@
 #ifdef HAVE_GTK
 
 #define GTK_DISABLE_DEPRECATED
-
 #include <gtk/gtk.h>
 
 typedef struct _GtkSelectDomainDialog GtkSelectDomainDialog;
@@ -74,6 +73,14 @@ struct _GtkSelectHostDialogClass
 #define GTK_SELECT_HOST_DIALOG_CLASS(klass)  GTK_CHECK_CLASS_CAST (klass, gtk_select_host_dialog_class_get_type (), GtkSelectHostDialogClass)
 #define IS_GTK_SELECT_HOST_DIALOG(obj)       GTK_CHECK_TYPE (obj, gtk_select_host_dialog_get_type ())
 
+GtkWidget *gtk_select_domain_dialog_new (struct dcerpc_pipe *sam_pipe);
+GType gtk_select_domain_dialog_get_type (void);
+struct policy_handle gtk_select_domain_dialog_get_handle(GtkSelectDomainDialog *d);
+GtkWidget *gtk_select_host_dialog_new (struct dcerpc_pipe *sam_pipe, BOOL nocredentials);
+const char *gtk_select_host_dialog_get_host (GtkSelectHostDialog *d);
+GType gtk_select_host_dialog_get_type (void);
+
+
 #endif
 
 #endif
index 00665839730f27061649b87fedc2a0c7ec12eb45..34ee0315cb2ea73ef9d8d123639fd17c4cede968 100644 (file)
@@ -6,7 +6,8 @@
 NOPROTO = YES
 INIT_OBJ_FILES = gtk/common/gtk-smb.o 
 ADD_OBJ_FILES = gtk/common/select.o \
-               gtk/common/gtk_events.o
+               gtk/common/gtk_events.o \
+               gtk/common/credentials.o
 REQUIRED_SUBSYSTEMS = CHARSET LIBBASIC EXT_LIB_gtk RPC_NDR_SAMR
 # End SUBSYSTEM GTKSMB
 ##############################