r5932: Use cli_credentials somewhat more in the Gtk+ code
[Samba/gebeck_regimport.git] / source4 / gtk / common / select.c
blob269a84022035f3e6fdca2eea9f9dbea6514b5487
1 /*
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 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.
22 #include "includes.h"
23 #include "librpc/gen_ndr/ndr_samr.h"
24 #include "gtk/common/select.h"
25 #include "gtk/common/gtk-smb.h"
27 /* GtkSelectDomainDialog */
29 const char *gtk_select_domain_dialog_get_domain(GtkSelectDomainDialog *d)
31 return gtk_entry_get_text(GTK_ENTRY(d->entry_domain));
34 void gtk_select_domain_dialog_init (GtkSelectDomainDialog *select_domain_dialog)
36 GtkWidget *dialog_vbox1;
37 GtkWidget *hbox1;
38 GtkWidget *label1;
39 GtkWidget *scrolledwindow1;
40 GtkWidget *dialog_action_area1;
41 GtkWidget *cancelbutton1;
42 GtkWidget *okbutton1;
43 GtkCellRenderer *renderer;
44 GtkTreeViewColumn *curcol;
46 gtk_window_set_title (GTK_WINDOW (select_domain_dialog), "Select Domain");
48 dialog_vbox1 = GTK_DIALOG (select_domain_dialog)->vbox;
50 hbox1 = gtk_hbox_new (FALSE, 0);
51 gtk_box_pack_start (GTK_BOX (dialog_vbox1), hbox1, TRUE, TRUE, 0);
53 label1 = gtk_label_new ("Domain:");
54 gtk_box_pack_start (GTK_BOX (hbox1), label1, FALSE, FALSE, 0);
56 select_domain_dialog->entry_domain = gtk_entry_new ();
57 gtk_box_pack_start (GTK_BOX (hbox1), select_domain_dialog->entry_domain, TRUE, TRUE, 0);
59 scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
60 gtk_box_pack_start (GTK_BOX (dialog_vbox1), scrolledwindow1, TRUE, TRUE, 0);
62 select_domain_dialog->list_domains = gtk_tree_view_new ();
63 gtk_container_add (GTK_CONTAINER (scrolledwindow1), select_domain_dialog->list_domains);
65 curcol = gtk_tree_view_column_new ();
66 gtk_tree_view_column_set_title(curcol, "Name");
67 renderer = gtk_cell_renderer_text_new();
68 gtk_tree_view_column_pack_start(curcol, renderer, True);
69 gtk_tree_view_append_column(GTK_TREE_VIEW(select_domain_dialog->list_domains), curcol);
70 gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
72 select_domain_dialog->store_domains = gtk_list_store_new(1, G_TYPE_STRING);
73 gtk_tree_view_set_model(GTK_TREE_VIEW(select_domain_dialog->list_domains), GTK_TREE_MODEL(select_domain_dialog->store_domains));
74 g_object_unref(select_domain_dialog->store_domains);
76 dialog_action_area1 = GTK_DIALOG (select_domain_dialog)->action_area;
77 gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END);
79 cancelbutton1 = gtk_button_new_from_stock ("gtk-cancel");
80 gtk_dialog_add_action_widget (GTK_DIALOG (select_domain_dialog), cancelbutton1, GTK_RESPONSE_CANCEL);
81 GTK_WIDGET_SET_FLAGS (cancelbutton1, GTK_CAN_DEFAULT);
83 okbutton1 = gtk_button_new_from_stock ("gtk-ok");
84 gtk_dialog_add_action_widget (GTK_DIALOG (select_domain_dialog), okbutton1, GTK_RESPONSE_OK);
85 gtk_widget_show_all(dialog_vbox1);
86 GTK_WIDGET_SET_FLAGS (okbutton1, GTK_CAN_DEFAULT);
89 struct policy_handle gtk_select_domain_dialog_get_handle(GtkSelectDomainDialog *d)
91 struct policy_handle h;
94 /* FIXME */
95 return h;
98 GType gtk_select_domain_dialog_get_type (void)
100 static GType mytype = 0;
102 if (!mytype)
104 static const GTypeInfo myinfo =
106 sizeof (GtkSelectDomainDialogClass),
107 NULL,
108 NULL,
109 NULL,
110 NULL,
111 NULL,
112 sizeof(GtkSelectDomainDialog),
114 (GInstanceInitFunc) gtk_select_domain_dialog_init,
117 mytype = g_type_register_static (GTK_TYPE_DIALOG,
118 "GtkSelectDomainDialog", &myinfo, 0);
121 return mytype;
124 GtkWidget *gtk_select_domain_dialog_new (struct dcerpc_pipe *sam_pipe)
126 GtkSelectDomainDialog *d = g_object_new(gtk_select_domain_dialog_get_type (), NULL);
127 NTSTATUS status;
128 struct samr_EnumDomains r;
129 struct samr_Connect cr;
130 struct samr_Close dr;
131 struct policy_handle handle;
132 uint32_t resume_handle = 0;
133 int i;
134 TALLOC_CTX *mem_ctx = talloc_init("gtk_select_domain_dialog_new");
136 d->sam_pipe = sam_pipe;
138 cr.in.system_name = 0;
139 cr.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
140 cr.out.connect_handle = &handle;
142 status = dcerpc_samr_Connect(sam_pipe, mem_ctx, &cr);
143 if (!NT_STATUS_IS_OK(status)) {
144 gtk_show_ntstatus(NULL, "Running Connect on SAMR", status);
145 talloc_free(mem_ctx);
146 return GTK_WIDGET(d);
149 r.in.connect_handle = &handle;
150 r.in.resume_handle = &resume_handle;
151 r.in.buf_size = (uint32_t)-1;
152 r.out.resume_handle = &resume_handle;
154 status = dcerpc_samr_EnumDomains(sam_pipe, mem_ctx, &r);
155 if (!NT_STATUS_IS_OK(status)) {
156 gtk_show_ntstatus(NULL, "Enumerating domains", status);
157 } else if (r.out.sam) {
158 for (i=0;i<r.out.sam->count;i++) {
159 GtkTreeIter iter;
160 gtk_list_store_append(d->store_domains, &iter);
161 gtk_list_store_set (d->store_domains, &iter, 0, r.out.sam->entries[i].name.string, -1);
165 dr.in.handle = &handle;
166 dr.out.handle = &handle;
168 status = dcerpc_samr_Close(sam_pipe, mem_ctx, &dr);
169 if (!NT_STATUS_IS_OK(status)) {
170 gtk_show_ntstatus(NULL, "Closing SAMR connection", status);
171 talloc_free(mem_ctx);
172 return GTK_WIDGET ( d );
175 talloc_free(mem_ctx);
177 return GTK_WIDGET ( d );
181 /* GtkSelectHostDialog */
182 const char *gtk_select_host_dialog_get_host (GtkSelectHostDialog *d)
184 return gtk_entry_get_text(GTK_ENTRY(d->entry_host));
187 void gtk_select_host_dialog_init (GtkSelectHostDialog *select_host_dialog)
189 GtkWidget *dialog_vbox2;
190 GtkWidget *hbox2;
191 GtkWidget *label2;
192 GtkWidget *scrolledwindow2;
193 GtkWidget *dialog_action_area2;
194 GtkWidget *cancelbutton2;
195 GtkWidget *okbutton2;
197 gtk_window_set_title (GTK_WINDOW (select_host_dialog), "Select Host");
199 dialog_vbox2 = GTK_DIALOG (select_host_dialog)->vbox;
201 hbox2 = gtk_hbox_new (FALSE, 0);
202 gtk_box_pack_start (GTK_BOX (dialog_vbox2), hbox2, TRUE, TRUE, 0);
204 label2 = gtk_label_new ("Host");
205 gtk_box_pack_start (GTK_BOX (hbox2), label2, FALSE, FALSE, 0);
207 select_host_dialog->entry_host = gtk_entry_new ();
208 gtk_box_pack_start (GTK_BOX (hbox2), select_host_dialog->entry_host, TRUE, TRUE, 0);
210 scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
211 gtk_box_pack_start (GTK_BOX (dialog_vbox2), scrolledwindow2, TRUE, TRUE, 0);
213 select_host_dialog->tree_host = gtk_tree_view_new ();
214 gtk_container_add (GTK_CONTAINER (scrolledwindow2), select_host_dialog->tree_host);
216 select_host_dialog->store_host = gtk_tree_store_new(1, G_TYPE_STRING);
217 gtk_tree_view_set_model(GTK_TREE_VIEW(select_host_dialog->tree_host), GTK_TREE_MODEL(select_host_dialog->store_host));
218 g_object_unref(select_host_dialog->store_host);
220 dialog_action_area2 = GTK_DIALOG (select_host_dialog)->action_area;
221 gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area2), GTK_BUTTONBOX_END);
223 cancelbutton2 = gtk_button_new_from_stock ("gtk-cancel");
224 gtk_dialog_add_action_widget (GTK_DIALOG (select_host_dialog), cancelbutton2, GTK_RESPONSE_CANCEL);
225 GTK_WIDGET_SET_FLAGS (cancelbutton2, GTK_CAN_DEFAULT);
227 okbutton2 = gtk_button_new_from_stock ("gtk-ok");
228 gtk_widget_show_all (dialog_vbox2);
229 gtk_dialog_add_action_widget (GTK_DIALOG (select_host_dialog), okbutton2, GTK_RESPONSE_OK);
230 GTK_WIDGET_SET_FLAGS (okbutton2, GTK_CAN_DEFAULT);
233 GType gtk_select_host_dialog_get_type (void)
235 static GType mytype = 0;
237 if (!mytype)
239 static const GTypeInfo myinfo =
241 sizeof (GtkSelectHostDialogClass),
242 NULL,
243 NULL,
244 NULL,
245 NULL,
246 NULL,
247 sizeof(GtkSelectHostDialog),
249 (GInstanceInitFunc) gtk_select_host_dialog_init,
252 mytype = g_type_register_static (GTK_TYPE_DIALOG,
253 "GtkSelectHostDialog", &myinfo, 0);
256 return mytype;
259 GtkWidget *gtk_select_host_dialog_new (struct sam_pipe *sam_pipe, BOOL nocredentials)
261 return GTK_WIDGET ( g_object_new (gtk_select_host_dialog_get_type (), NULL ));