2 Unix SMB/CIFS implementation.
3 SMB-related GTK+ functions
5 Copyright (C) Jelmer Vernooij 2004-2005
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "gtk/common/gtk-smb.h"
24 #include "gtk/common/select.h"
26 #include "librpc/rpc/dcerpc.h"
27 #include "auth/credentials/credentials.h"
30 * Dialog error showing a WERROR
32 void gtk_show_werror(GtkWidget
*win
, const char *message
, WERROR err
)
34 GtkWidget
*dialog
= gtk_message_dialog_new( GTK_WINDOW(win
),
35 GTK_DIALOG_DESTROY_WITH_PARENT
,
38 "%s: %s\n", message
?message
: "Windows error",
40 gtk_dialog_run (GTK_DIALOG (dialog
));
41 gtk_widget_destroy (dialog
);
45 * GTK+ dialog showing a NTSTATUS error
47 void gtk_show_ntstatus(GtkWidget
*win
, const char *message
, NTSTATUS status
)
49 GtkWidget
*dialog
= gtk_message_dialog_new( GTK_WINDOW(win
),
50 GTK_DIALOG_DESTROY_WITH_PARENT
,
53 "%s: %s\n", message
?message
:"Windows error",
55 gtk_dialog_run (GTK_DIALOG (dialog
));
56 gtk_widget_destroy (dialog
);
59 static void on_browse_activate (GtkButton
*button
, gpointer user_data
)
61 GtkRpcBindingDialog
*rbd
= user_data
;
62 GtkWidget
*shd
= gtk_select_host_dialog_new(rbd
->sam_pipe
);
63 if(gtk_dialog_run(GTK_DIALOG(shd
)) == GTK_RESPONSE_ACCEPT
) {
64 gtk_entry_set_text(GTK_ENTRY(rbd
->entry_host
), gtk_select_host_dialog_get_host(GTK_SELECT_HOST_DIALOG(shd
)));
67 gtk_widget_destroy(GTK_WIDGET(shd
));
70 static void on_ncalrpc_toggled(GtkToggleButton
*tb
, GtkRpcBindingDialog
*d
)
72 gtk_widget_set_sensitive(d
->frame_host
, !gtk_toggle_button_get_active(tb
));
75 static void gtk_rpc_binding_dialog_init (GtkRpcBindingDialog
*gtk_rpc_binding_dialog
)
77 GtkWidget
*dialog_vbox1
;
80 GtkWidget
*frame_transport
;
86 GtkWidget
*frame_security
;
88 GtkWidget
*btn_browse
;
89 GtkWidget
*dialog_action_area1
;
90 GtkWidget
*btn_cancel
;
91 GtkWidget
*btn_connect
;
92 GSList
*transport_smb_group
= NULL
;
94 gtk_rpc_binding_dialog
->mem_ctx
= talloc_init("gtk_rcp_binding_dialog");
96 gtk_window_set_title (GTK_WINDOW (gtk_rpc_binding_dialog
), "Connect");
98 dialog_vbox1
= GTK_DIALOG (gtk_rpc_binding_dialog
)->vbox
;
100 vbox1
= gtk_vbox_new (FALSE
, 0);
101 gtk_box_pack_start (GTK_BOX (dialog_vbox1
), vbox1
, TRUE
, TRUE
, 0);
103 frame_transport
= gtk_frame_new (NULL
);
104 gtk_box_pack_start (GTK_BOX (vbox1
), frame_transport
, TRUE
, TRUE
, 0);
106 vbox6
= gtk_vbox_new (FALSE
, 0);
107 gtk_container_add (GTK_CONTAINER (frame_transport
), vbox6
);
109 gtk_rpc_binding_dialog
->transport_ncalrpc
= gtk_radio_button_new_with_mnemonic (NULL
, "Local Host");
110 gtk_box_pack_start (GTK_BOX (vbox6
), gtk_rpc_binding_dialog
->transport_ncalrpc
, FALSE
, FALSE
, 0);
111 gtk_radio_button_set_group (GTK_RADIO_BUTTON (gtk_rpc_binding_dialog
->transport_ncalrpc
), transport_smb_group
);
112 transport_smb_group
= gtk_radio_button_get_group (GTK_RADIO_BUTTON (gtk_rpc_binding_dialog
->transport_ncalrpc
));
115 gtk_rpc_binding_dialog
->transport_smb
= gtk_radio_button_new_with_mnemonic (NULL
, "RPC over SMB over TCP/IP");
116 gtk_box_pack_start (GTK_BOX (vbox6
), gtk_rpc_binding_dialog
->transport_smb
, FALSE
, FALSE
, 0);
117 gtk_radio_button_set_group (GTK_RADIO_BUTTON (gtk_rpc_binding_dialog
->transport_smb
), transport_smb_group
);
118 transport_smb_group
= gtk_radio_button_get_group (GTK_RADIO_BUTTON (gtk_rpc_binding_dialog
->transport_smb
));
119 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_rpc_binding_dialog
->transport_smb
), TRUE
);
121 gtk_rpc_binding_dialog
->transport_tcp_ip
= gtk_radio_button_new_with_mnemonic (NULL
, "RPC over TCP/IP");
122 gtk_box_pack_start (GTK_BOX (vbox6
), gtk_rpc_binding_dialog
->transport_tcp_ip
, FALSE
, FALSE
, 0);
123 gtk_radio_button_set_group (GTK_RADIO_BUTTON (gtk_rpc_binding_dialog
->transport_tcp_ip
), transport_smb_group
);
124 transport_smb_group
= gtk_radio_button_get_group (GTK_RADIO_BUTTON (gtk_rpc_binding_dialog
->transport_tcp_ip
));
126 label1
= gtk_label_new ("Transport");
127 gtk_frame_set_label_widget (GTK_FRAME (frame_transport
), label1
);
129 gtk_rpc_binding_dialog
->frame_host
= gtk_frame_new (NULL
);
130 gtk_box_pack_start (GTK_BOX (vbox1
), gtk_rpc_binding_dialog
->frame_host
, TRUE
, TRUE
, 0);
132 hbox1
= gtk_hbox_new (FALSE
, 0);
133 gtk_container_add (GTK_CONTAINER (gtk_rpc_binding_dialog
->frame_host
), hbox1
);
135 lbl_name
= gtk_label_new ("Name");
136 gtk_box_pack_start (GTK_BOX (hbox1
), lbl_name
, TRUE
, TRUE
, 0);
138 gtk_rpc_binding_dialog
->entry_host
= gtk_entry_new ();
139 gtk_box_pack_start (GTK_BOX (hbox1
), gtk_rpc_binding_dialog
->entry_host
, TRUE
, TRUE
, 0);
141 if(gtk_rpc_binding_dialog
->sam_pipe
)
143 btn_browse
= gtk_button_new_with_label ("Browse");
144 gtk_box_pack_start (GTK_BOX (hbox1
), btn_browse
, TRUE
, TRUE
, 0);
146 g_signal_connect ((gpointer
) btn_browse
, "pressed",
147 G_CALLBACK (on_browse_activate
),
148 gtk_rpc_binding_dialog
);
151 label2
= gtk_label_new ("Host");
152 gtk_frame_set_label_widget (GTK_FRAME (gtk_rpc_binding_dialog
->frame_host
), label2
);
154 frame_security
= gtk_frame_new (NULL
);
156 label3
= gtk_label_new ("Security");
157 gtk_frame_set_label_widget (GTK_FRAME (frame_security
), label3
);
159 gtk_box_pack_start (GTK_BOX (vbox1
), frame_security
, TRUE
, TRUE
, 0);
161 vbox2
= gtk_vbox_new (FALSE
, 0);
162 gtk_container_add (GTK_CONTAINER (frame_security
), vbox2
);
164 gtk_rpc_binding_dialog
->chk_sign
= gtk_check_button_new_with_mnemonic ("S_ign");
165 gtk_box_pack_start (GTK_BOX (vbox2
), gtk_rpc_binding_dialog
->chk_sign
, FALSE
, FALSE
, 0);
167 gtk_rpc_binding_dialog
->chk_seal
= gtk_check_button_new_with_mnemonic ("_Seal");
168 gtk_box_pack_start (GTK_BOX (vbox2
), gtk_rpc_binding_dialog
->chk_seal
, FALSE
, FALSE
, 0);
170 dialog_action_area1
= GTK_DIALOG (gtk_rpc_binding_dialog
)->action_area
;
171 gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1
), GTK_BUTTONBOX_END
);
173 btn_cancel
= gtk_button_new_from_stock ("gtk-cancel");
174 gtk_dialog_add_action_widget (GTK_DIALOG (gtk_rpc_binding_dialog
), btn_cancel
, GTK_RESPONSE_CANCEL
);
175 GTK_WIDGET_SET_FLAGS (btn_cancel
, GTK_CAN_DEFAULT
);
177 btn_connect
= gtk_button_new_with_mnemonic ("C_onnect");
178 gtk_dialog_add_action_widget (GTK_DIALOG (gtk_rpc_binding_dialog
), btn_connect
, GTK_RESPONSE_ACCEPT
);
179 gtk_container_set_border_width (GTK_CONTAINER (btn_connect
), 1);
180 GTK_WIDGET_SET_FLAGS (btn_connect
, GTK_CAN_DEFAULT
);
182 g_signal_connect ((gpointer
) gtk_rpc_binding_dialog
->transport_ncalrpc
, "toggled",
183 G_CALLBACK (on_ncalrpc_toggled
),
184 gtk_rpc_binding_dialog
);
187 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(gtk_rpc_binding_dialog
->transport_ncalrpc
), TRUE
);
188 gtk_widget_show_all(dialog_vbox1
);
190 gtk_widget_grab_focus (btn_connect
);
191 gtk_widget_grab_default (btn_connect
);
194 GType
gtk_rpc_binding_dialog_get_type (void)
196 static GType mytype
= 0;
200 static const GTypeInfo myinfo
=
202 sizeof (GtkRpcBindingDialogClass
),
208 sizeof(GtkRpcBindingDialog
),
210 (GInstanceInitFunc
) gtk_rpc_binding_dialog_init
,
213 mytype
= g_type_register_static (GTK_TYPE_DIALOG
,
214 "GtkRpcBindingDialog", &myinfo
, 0);
221 * Create a new GTK+ dialog asking for binding information for
224 * Optionally gets a sam pipe that will be used to look up users
226 GtkWidget
*gtk_rpc_binding_dialog_new (struct dcerpc_pipe
*sam_pipe
)
228 GtkRpcBindingDialog
*d
= GTK_RPC_BINDING_DIALOG ( g_object_new (gtk_rpc_binding_dialog_get_type (), NULL
));
229 d
->sam_pipe
= sam_pipe
;
230 return GTK_WIDGET(d
);
233 const char *gtk_rpc_binding_dialog_get_host(GtkRpcBindingDialog
*d
)
235 return gtk_entry_get_text(GTK_ENTRY(d
->entry_host
));
238 struct dcerpc_binding
*gtk_rpc_binding_dialog_get_binding(GtkRpcBindingDialog
*d
, TALLOC_CTX
*mem_ctx
)
240 struct dcerpc_binding
*binding
= talloc(mem_ctx
, struct dcerpc_binding
);
242 ZERO_STRUCT(binding
->object
);
244 /* Format: TRANSPORT:host[\pipe\foo,foo,foo] */
246 binding
->host
= talloc_strdup(mem_ctx
, gtk_entry_get_text(GTK_ENTRY(d
->entry_host
)));
247 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(d
->transport_tcp_ip
))) {
248 binding
->transport
= NCACN_IP_TCP
;
249 } else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(d
->transport_ncalrpc
))) {
250 binding
->transport
= NCALRPC
;
251 binding
->host
= NULL
;
253 binding
->transport
= NCACN_NP
;
256 binding
->options
= NULL
;
258 binding
->endpoint
= NULL
;
260 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(d
->chk_seal
))) {
261 binding
->flags
|= DCERPC_SEAL
;
264 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(d
->chk_sign
))) {
265 binding
->flags
|= DCERPC_SIGN
;
271 const char *gtk_rpc_binding_dialog_get_binding_string(GtkRpcBindingDialog
*d
, TALLOC_CTX
*mem_ctx
)
273 return dcerpc_binding_string(mem_ctx
, gtk_rpc_binding_dialog_get_binding(d
, mem_ctx
));
276 GtkWidget
*create_gtk_samba_about_dialog (const char *appname
)
278 GtkWidget
*samba_about_dialog
;
279 GtkWidget
*dialog_vbox1
;
284 GtkWidget
*dialog_action_area1
;
285 GtkWidget
*okbutton1
;
287 samba_about_dialog
= gtk_dialog_new ();
288 gtk_window_set_title (GTK_WINDOW (samba_about_dialog
), "About");
290 dialog_vbox1
= GTK_DIALOG (samba_about_dialog
)->vbox
;
292 /* FIXME image1 = create_pixmap (samba_about_dialog, "slmed.png");
293 gtk_box_pack_start (GTK_BOX (dialog_vbox1), image1, TRUE, TRUE, 0);*/
295 label1
= gtk_label_new (appname
);
296 gtk_box_pack_start (GTK_BOX (dialog_vbox1
), label1
, FALSE
, FALSE
, 0);
298 label2
= gtk_label_new (SAMBA_VERSION_STRING
);
299 gtk_box_pack_start (GTK_BOX (dialog_vbox1
), label2
, FALSE
, FALSE
, 0);
301 label3
= gtk_label_new_with_mnemonic ("Part of Samba <http://www.samba.org/>");
302 gtk_box_pack_start (GTK_BOX (dialog_vbox1
), label3
, FALSE
, FALSE
, 0);
304 label4
= gtk_label_new ("\302\251 1992-2006 The Samba Team");
305 gtk_box_pack_start (GTK_BOX (dialog_vbox1
), label4
, FALSE
, FALSE
, 0);
307 dialog_action_area1
= GTK_DIALOG (samba_about_dialog
)->action_area
;
308 gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1
), GTK_BUTTONBOX_END
);
310 okbutton1
= gtk_button_new_from_stock ("gtk-ok");
311 gtk_dialog_add_action_widget (GTK_DIALOG (samba_about_dialog
), okbutton1
, GTK_RESPONSE_OK
);
312 GTK_WIDGET_SET_FLAGS (okbutton1
, GTK_CAN_DEFAULT
);
313 gtk_widget_show_all(dialog_vbox1
);
315 return samba_about_dialog
;