2 Unix SMB/CIFS implementation.
3 SMB-related GTK+ functions
5 Copyright (C) Jelmer Vernooij 2004
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 3 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.
29 #include <gen_ndr/ndr_samr_c.h>
30 #include "common/select.h"
31 #include "common/gtk-smb.h"
32 #include <credentials.h>
34 /* GtkSelectDomainDialog */
36 const char *gtk_select_domain_dialog_get_domain(GtkSelectDomainDialog *d)
38 return gtk_entry_get_text(GTK_ENTRY(d->entry_domain));
41 static void gtk_select_domain_dialog_init (GtkSelectDomainDialog *select_domain_dialog)
43 GtkWidget *dialog_vbox1;
46 GtkWidget *scrolledwindow1;
47 GtkWidget *dialog_action_area1;
48 GtkWidget *cancelbutton1;
50 GtkCellRenderer *renderer;
51 GtkTreeViewColumn *curcol;
53 gtk_window_set_title (GTK_WINDOW (select_domain_dialog), "Select Domain");
55 dialog_vbox1 = GTK_DIALOG (select_domain_dialog)->vbox;
57 hbox1 = gtk_hbox_new (FALSE, 0);
58 gtk_box_pack_start (GTK_BOX (dialog_vbox1), hbox1, TRUE, TRUE, 0);
60 label1 = gtk_label_new ("Domain:");
61 gtk_box_pack_start (GTK_BOX (hbox1), label1, FALSE, FALSE, 0);
63 select_domain_dialog->entry_domain = gtk_entry_new ();
64 gtk_box_pack_start (GTK_BOX (hbox1), select_domain_dialog->entry_domain, TRUE, TRUE, 0);
66 scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
67 gtk_box_pack_start (GTK_BOX (dialog_vbox1), scrolledwindow1, TRUE, TRUE, 0);
69 select_domain_dialog->list_domains = gtk_tree_view_new ();
70 gtk_container_add (GTK_CONTAINER (scrolledwindow1), select_domain_dialog->list_domains);
72 curcol = gtk_tree_view_column_new ();
73 gtk_tree_view_column_set_title(curcol, "Name");
74 renderer = gtk_cell_renderer_text_new();
75 gtk_tree_view_column_pack_start(curcol, renderer, TRUE);
76 gtk_tree_view_append_column(GTK_TREE_VIEW(select_domain_dialog->list_domains), curcol);
77 gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
79 select_domain_dialog->store_domains = gtk_list_store_new(1, G_TYPE_STRING);
80 gtk_tree_view_set_model(GTK_TREE_VIEW(select_domain_dialog->list_domains), GTK_TREE_MODEL(select_domain_dialog->store_domains));
81 g_object_unref(select_domain_dialog->store_domains);
83 dialog_action_area1 = GTK_DIALOG (select_domain_dialog)->action_area;
84 gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END);
86 cancelbutton1 = gtk_button_new_from_stock ("gtk-cancel");
87 gtk_dialog_add_action_widget (GTK_DIALOG (select_domain_dialog), cancelbutton1, GTK_RESPONSE_CANCEL);
88 gtk_widget_set_can_default(cancelbutton1, TRUE);
90 okbutton1 = gtk_button_new_from_stock ("gtk-ok");
91 gtk_dialog_add_action_widget (GTK_DIALOG (select_domain_dialog), okbutton1, GTK_RESPONSE_OK);
92 gtk_widget_show_all(dialog_vbox1);
93 gtk_widget_set_can_default(okbutton1, TRUE);
96 struct policy_handle gtk_select_domain_dialog_get_handle(GtkSelectDomainDialog *d)
98 struct policy_handle h;
105 GType gtk_select_domain_dialog_get_type (void)
107 static GType mytype = 0;
111 static const GTypeInfo myinfo =
113 sizeof (GtkSelectDomainDialogClass),
119 sizeof(GtkSelectDomainDialog),
121 (GInstanceInitFunc) gtk_select_domain_dialog_init,
124 mytype = g_type_register_static (GTK_TYPE_DIALOG,
125 "GtkSelectDomainDialog", &myinfo, 0);
131 GtkWidget *gtk_select_domain_dialog_new (struct dcerpc_binding_handle *sam_pipe)
133 GtkSelectDomainDialog *d = g_object_new(gtk_select_domain_dialog_get_type (), NULL);
134 NTSTATUS status, result;
135 struct samr_SamArray *sam;
136 struct policy_handle handle;
137 uint32_t resume_handle = 0;
138 uint32_t num_entries;
140 TALLOC_CTX *mem_ctx = talloc_init("gtk_select_domain_dialog_new");
142 d->sam_pipe = sam_pipe;
144 status = dcerpc_samr_Connect(sam_pipe, mem_ctx, 0,
145 SEC_FLAG_MAXIMUM_ALLOWED, &handle, &result);
146 if (!NT_STATUS_IS_OK(status)) {
147 gtk_show_ntstatus(NULL, "Running Connect on SAMR", status);
148 talloc_free(mem_ctx);
149 return GTK_WIDGET(d);
152 status = dcerpc_samr_EnumDomains(sam_pipe, mem_ctx, &handle, &resume_handle, &sam, -1, &num_entries, &result);
153 if (!NT_STATUS_IS_OK(status)) {
154 gtk_show_ntstatus(NULL, "Enumerating domains", status);
155 } else if (sam != NULL) {
156 for (i=0;i<sam->count;i++) {
158 gtk_list_store_append(d->store_domains, &iter);
159 gtk_list_store_set (d->store_domains, &iter, 0, sam->entries[i].name.string, -1);
163 status = dcerpc_samr_Close(sam_pipe, mem_ctx, &handle, &result);
164 if (!NT_STATUS_IS_OK(status)) {
165 gtk_show_ntstatus(NULL, "Closing SAMR connection", status);
166 talloc_free(mem_ctx);
167 return GTK_WIDGET ( d );
170 talloc_free(mem_ctx);
172 return GTK_WIDGET ( d );
176 /* GtkSelectHostDialog */
177 const char *gtk_select_host_dialog_get_host (GtkSelectHostDialog *d)
179 return gtk_entry_get_text(GTK_ENTRY(d->entry_host));
182 static void gtk_select_host_dialog_init (GtkSelectHostDialog *select_host_dialog)
184 GtkWidget *dialog_vbox2;
187 GtkWidget *scrolledwindow2;
188 GtkWidget *dialog_action_area2;
189 GtkWidget *cancelbutton2;
190 GtkWidget *okbutton2;
192 gtk_window_set_title (GTK_WINDOW (select_host_dialog), "Select Host");
194 dialog_vbox2 = GTK_DIALOG (select_host_dialog)->vbox;
196 hbox2 = gtk_hbox_new (FALSE, 0);
197 gtk_box_pack_start (GTK_BOX (dialog_vbox2), hbox2, TRUE, TRUE, 0);
199 label2 = gtk_label_new ("Host");
200 gtk_box_pack_start (GTK_BOX (hbox2), label2, FALSE, FALSE, 0);
202 select_host_dialog->entry_host = gtk_entry_new ();
203 gtk_box_pack_start (GTK_BOX (hbox2), select_host_dialog->entry_host, TRUE, TRUE, 0);
205 scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
206 gtk_box_pack_start (GTK_BOX (dialog_vbox2), scrolledwindow2, TRUE, TRUE, 0);
208 select_host_dialog->tree_host = gtk_tree_view_new ();
209 gtk_container_add (GTK_CONTAINER (scrolledwindow2), select_host_dialog->tree_host);
211 select_host_dialog->store_host = gtk_tree_store_new(1, G_TYPE_STRING);
212 gtk_tree_view_set_model(GTK_TREE_VIEW(select_host_dialog->tree_host), GTK_TREE_MODEL(select_host_dialog->store_host));
213 g_object_unref(select_host_dialog->store_host);
215 dialog_action_area2 = GTK_DIALOG (select_host_dialog)->action_area;
216 gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area2), GTK_BUTTONBOX_END);
218 cancelbutton2 = gtk_button_new_from_stock ("gtk-cancel");
219 gtk_dialog_add_action_widget (GTK_DIALOG (select_host_dialog), cancelbutton2, GTK_RESPONSE_CANCEL);
220 gtk_widget_set_can_default(cancelbutton2, TRUE);
222 okbutton2 = gtk_button_new_from_stock ("gtk-ok");
223 gtk_widget_show_all (dialog_vbox2);
224 gtk_dialog_add_action_widget (GTK_DIALOG (select_host_dialog), okbutton2, GTK_RESPONSE_OK);
225 gtk_widget_set_can_default(okbutton2, TRUE);
228 GType gtk_select_host_dialog_get_type (void)
230 static GType mytype = 0;
234 static const GTypeInfo myinfo =
236 sizeof (GtkSelectHostDialogClass),
242 sizeof(GtkSelectHostDialog),
244 (GInstanceInitFunc) gtk_select_host_dialog_init,
247 mytype = g_type_register_static (GTK_TYPE_DIALOG,
248 "GtkSelectHostDialog", &myinfo, 0);
254 GtkWidget *gtk_select_host_dialog_new (struct dcerpc_binding_handle *sam_pipe)
256 return GTK_WIDGET ( g_object_new (gtk_select_host_dialog_get_type (), NULL ));
260 * Connect to a specific interface, but ask the user
261 * for information not specified
263 struct dcerpc_binding_handle *gtk_connect_rpc_interface(TALLOC_CTX *mem_ctx,
264 struct tevent_context *ev_ctx,
265 struct loadparm_context *lp_ctx,
266 const struct ndr_interface_table *table)
268 GtkRpcBindingDialog *d;
270 struct dcerpc_binding_handle *pipe;
271 struct cli_credentials *cred;
274 d = SAMBAGTK_RPC_BINDING_DIALOG(gtk_rpc_binding_dialog_new(NULL));
275 result = gtk_dialog_run(GTK_DIALOG(d));
277 if (result != GTK_RESPONSE_ACCEPT) {
278 gtk_widget_destroy(GTK_WIDGET(d));
282 cred = cli_credentials_init(mem_ctx);
283 cli_credentials_guess(cred, lp_ctx);
284 cli_credentials_set_gtk_callbacks(cred);
286 status = dcerpc_pipe_connect_b(mem_ctx, &pipe,
287 gtk_rpc_binding_dialog_get_binding(d, mem_ctx),
288 table, cred, ev_ctx, lp_ctx);
290 if(!NT_STATUS_IS_OK(status)) {
291 gtk_show_ntstatus(NULL, "While connecting to interface", status);
292 gtk_widget_destroy(GTK_WIDGET(d));
297 gtk_widget_destroy(GTK_WIDGET(d));