diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2005-03-23 01:02:29 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:11:12 -0500 |
commit | 9b48673ad9ed5cf2019df7111fe6ef89ad57573d (patch) | |
tree | 843cdf81bb15a79c9da532aea54f602bc7a59d54 /source4 | |
parent | df8c102ec9c64a44ae4b7aa3a47bdf33178f2dcf (diff) | |
download | samba-9b48673ad9ed5cf2019df7111fe6ef89ad57573d.tar.gz samba-9b48673ad9ed5cf2019df7111fe6ef89ad57573d.tar.bz2 samba-9b48673ad9ed5cf2019df7111fe6ef89ad57573d.zip |
r5987: Add credentials callback for gtk+. The gtk+ apps now no longer
ask for a password when kerberos is being used.
(This used to be commit 642ec7cbef6d392b49ed0fe86d1816d4953e30ad)
Diffstat (limited to 'source4')
-rw-r--r-- | source4/gtk/common/credentials.c | 95 | ||||
-rw-r--r-- | source4/gtk/common/gtk-smb.c | 31 | ||||
-rw-r--r-- | source4/gtk/common/gtk-smb.h | 14 | ||||
-rw-r--r-- | source4/gtk/common/select.c | 2 | ||||
-rw-r--r-- | source4/gtk/common/select.h | 9 | ||||
-rw-r--r-- | source4/gtk/config.mk | 3 |
6 files changed, 115 insertions, 39 deletions
diff --git a/source4/gtk/common/credentials.c b/source4/gtk/common/credentials.c new file mode 100644 index 0000000000..dce77220fd --- /dev/null +++ b/source4/gtk/common/credentials.c @@ -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; + } +} diff --git a/source4/gtk/common/gtk-smb.c b/source4/gtk/common/gtk-smb.c index a84f9f639d..f4458442f0 100644 --- a/source4/gtk/common/gtk-smb.c +++ b/source4/gtk/common/gtk-smb.c @@ -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; diff --git a/source4/gtk/common/gtk-smb.h b/source4/gtk/common/gtk-smb.h index 0a7bbcba00..2ff0a3be0c 100644 --- a/source4/gtk/common/gtk-smb.h +++ b/source4/gtk/common/gtk-smb.h @@ -22,8 +22,10 @@ #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 diff --git a/source4/gtk/common/select.c b/source4/gtk/common/select.c index 269a840220..2075806f96 100644 --- a/source4/gtk/common/select.c +++ b/source4/gtk/common/select.c @@ -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 )); } diff --git a/source4/gtk/common/select.h b/source4/gtk/common/select.h index 336359c322..4cbeb09b0d 100644 --- a/source4/gtk/common/select.h +++ b/source4/gtk/common/select.h @@ -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 diff --git a/source4/gtk/config.mk b/source4/gtk/config.mk index 0066583973..34ee0315cb 100644 --- a/source4/gtk/config.mk +++ b/source4/gtk/config.mk @@ -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 ############################## |