r2920: Support passing a handle to a SAMR pipe to a RPC Binding or Select
[samba.git] / source / gtk / common / select.c
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB-related GTK+ functions
4    
5    Copyright (C) Jelmer Vernooij 2004
6
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.
11    
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.
16    
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.
20 */
21
22 #include "includes.h"
23 #include "gtk-smb.h"
24
25 /* GtkSelectDomainDialog */
26
27 const char *gtk_select_domain_dialog_get_domain(GtkSelectDomainDialog *d)
28 {
29         return gtk_entry_get_text(GTK_ENTRY(d->entry_domain));
30 }
31
32 void gtk_select_domain_dialog_init (GtkSelectDomainDialog *select_domain_dialog)
33 {
34         GtkWidget *dialog_vbox1;
35         GtkWidget *hbox1;
36         GtkWidget *label1;
37         GtkWidget *scrolledwindow1;
38         GtkWidget *dialog_action_area1;
39         GtkWidget *cancelbutton1;
40         GtkWidget *okbutton1;
41         GtkCellRenderer *renderer;
42         GtkTreeViewColumn *curcol;
43
44         gtk_window_set_title (GTK_WINDOW (select_domain_dialog), "Select Domain");
45
46         dialog_vbox1 = GTK_DIALOG (select_domain_dialog)->vbox;
47         gtk_widget_show (dialog_vbox1);
48
49         hbox1 = gtk_hbox_new (FALSE, 0);
50         gtk_widget_show (hbox1);
51         gtk_box_pack_start (GTK_BOX (dialog_vbox1), hbox1, TRUE, TRUE, 0);
52
53         label1 = gtk_label_new ("Domain:");
54         gtk_widget_show (label1);
55         gtk_box_pack_start (GTK_BOX (hbox1), label1, FALSE, FALSE, 0);
56
57         select_domain_dialog->entry_domain = gtk_entry_new ();
58         gtk_widget_show (select_domain_dialog->entry_domain);
59         gtk_box_pack_start (GTK_BOX (hbox1), select_domain_dialog->entry_domain, TRUE, TRUE, 0);
60
61         scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
62         gtk_widget_show (scrolledwindow1);
63         gtk_box_pack_start (GTK_BOX (dialog_vbox1), scrolledwindow1, TRUE, TRUE, 0);
64
65         select_domain_dialog->list_domains = gtk_tree_view_new ();
66         gtk_widget_show (select_domain_dialog->list_domains);
67         gtk_container_add (GTK_CONTAINER (scrolledwindow1), select_domain_dialog->list_domains);
68
69         curcol = gtk_tree_view_column_new ();
70         gtk_tree_view_column_set_title(curcol, "Name");
71         renderer = gtk_cell_renderer_text_new();
72         gtk_tree_view_column_pack_start(curcol, renderer, True);
73         gtk_tree_view_append_column(GTK_TREE_VIEW(select_domain_dialog->list_domains), curcol);
74         gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
75
76         select_domain_dialog->store_domains = gtk_list_store_new(1, G_TYPE_STRING);
77         gtk_tree_view_set_model(GTK_TREE_VIEW(select_domain_dialog->list_domains), GTK_TREE_MODEL(select_domain_dialog->store_domains));
78         g_object_unref(select_domain_dialog->store_domains);
79
80         dialog_action_area1 = GTK_DIALOG (select_domain_dialog)->action_area;
81         gtk_widget_show (dialog_action_area1);
82         gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END);
83
84         cancelbutton1 = gtk_button_new_from_stock ("gtk-cancel");
85         gtk_widget_show (cancelbutton1);
86         gtk_dialog_add_action_widget (GTK_DIALOG (select_domain_dialog), cancelbutton1, GTK_RESPONSE_CANCEL);
87         GTK_WIDGET_SET_FLAGS (cancelbutton1, GTK_CAN_DEFAULT);
88
89         okbutton1 = gtk_button_new_from_stock ("gtk-ok");
90         gtk_widget_show (okbutton1);
91         gtk_dialog_add_action_widget (GTK_DIALOG (select_domain_dialog), okbutton1, GTK_RESPONSE_OK);
92         GTK_WIDGET_SET_FLAGS (okbutton1, GTK_CAN_DEFAULT);
93 }
94
95 struct policy_handle gtk_select_domain_dialog_get_handle(GtkSelectDomainDialog *d)
96 {
97         struct policy_handle h;
98         
99         
100         /* FIXME */
101         return h;
102 }
103
104 GType gtk_select_domain_dialog_get_type (void)
105 {
106         static GType mytype = 0;
107
108         if (!mytype)
109         {
110                 static const GTypeInfo myinfo =
111                 {
112                         sizeof (GtkSelectDomainDialogClass),
113                         NULL,
114                         NULL,
115                         NULL,
116                         NULL,
117                         NULL,
118                         sizeof(GtkSelectDomainDialog),
119                         0,
120                         (GInstanceInitFunc) gtk_select_domain_dialog_init,
121                 };
122
123                 mytype = g_type_register_static (GTK_TYPE_DIALOG,
124                                                                                  "GtkSelectDomainDialog", &myinfo, 0);
125         }
126
127         return mytype;
128 }
129                                                                                                                              
130 GtkWidget *gtk_select_domain_dialog_new (struct dcerpc_pipe *sam_pipe)
131 {
132         GtkSelectDomainDialog *d = gtk_type_new (gtk_select_domain_dialog_get_type ());
133         NTSTATUS status;
134         struct samr_EnumDomains r;
135         struct samr_Connect cr;
136         struct samr_Close dr;
137         struct policy_handle handle;
138         uint32_t resume_handle = 0;
139         int i;
140         TALLOC_CTX *mem_ctx = talloc_init("gtk_select_domain_dialog_new");
141
142         d->sam_pipe = sam_pipe;
143
144         cr.in.system_name = 0;
145         cr.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
146         cr.out.connect_handle = &handle;
147
148         status = dcerpc_samr_Connect(sam_pipe, mem_ctx, &cr);
149         if (!NT_STATUS_IS_OK(status)) {
150                 gtk_show_ntstatus(NULL, status);
151                 talloc_destroy(mem_ctx);
152                 return GTK_WIDGET(d);
153         }
154
155         r.in.connect_handle = &handle;
156         r.in.resume_handle = &resume_handle;
157         r.in.buf_size = (uint32_t)-1;
158         r.out.resume_handle = &resume_handle;
159
160         status = dcerpc_samr_EnumDomains(sam_pipe, mem_ctx, &r);
161         if (!NT_STATUS_IS_OK(status)) {
162                 gtk_show_ntstatus(NULL, status);
163         } else if (r.out.sam) {
164                 for (i=0;i<r.out.sam->count;i++) {
165                         GtkTreeIter iter;
166                         gtk_list_store_append(d->store_domains, &iter);
167                         gtk_list_store_set (d->store_domains, &iter, 0, r.out.sam->entries[i].name.name, -1);
168                 }
169         }
170
171         dr.in.handle = &handle;
172         dr.out.handle = &handle;
173
174         status = dcerpc_samr_Close(sam_pipe, mem_ctx, &dr);
175         if (!NT_STATUS_IS_OK(status)) {
176                 gtk_show_ntstatus(NULL, status);
177                 talloc_destroy(mem_ctx);
178                 return GTK_WIDGET ( d );
179         }
180
181         talloc_destroy(mem_ctx);
182
183         return GTK_WIDGET ( d );
184 }
185
186
187 /* GtkSelectHostDialog */
188 const char *gtk_select_host_dialog_get_host (GtkSelectHostDialog *d)
189 {
190         return gtk_entry_get_text(GTK_ENTRY(d->entry_host));
191 }
192
193 void gtk_select_host_dialog_init (GtkSelectHostDialog *select_host_dialog)
194 {
195         GtkWidget *dialog_vbox2;
196         GtkWidget *hbox2;
197         GtkWidget *label2;
198         GtkWidget *scrolledwindow2;
199         GtkWidget *dialog_action_area2;
200         GtkWidget *cancelbutton2;
201         GtkWidget *okbutton2;
202
203         gtk_window_set_title (GTK_WINDOW (select_host_dialog), "Select Host");
204
205         dialog_vbox2 = GTK_DIALOG (select_host_dialog)->vbox;
206         gtk_widget_show (dialog_vbox2);
207
208         hbox2 = gtk_hbox_new (FALSE, 0);
209         gtk_widget_show (hbox2);
210         gtk_box_pack_start (GTK_BOX (dialog_vbox2), hbox2, TRUE, TRUE, 0);
211
212         label2 = gtk_label_new ("Host");
213         gtk_widget_show (label2);
214         gtk_box_pack_start (GTK_BOX (hbox2), label2, FALSE, FALSE, 0);
215
216         select_host_dialog->entry_host = gtk_entry_new ();
217         gtk_widget_show (select_host_dialog->entry_host);
218         gtk_box_pack_start (GTK_BOX (hbox2), select_host_dialog->entry_host, TRUE, TRUE, 0);
219
220         scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
221         gtk_widget_show (scrolledwindow2);
222         gtk_box_pack_start (GTK_BOX (dialog_vbox2), scrolledwindow2, TRUE, TRUE, 0);
223
224         select_host_dialog->tree_host = gtk_tree_view_new ();
225         gtk_widget_show (select_host_dialog->tree_host);
226         gtk_container_add (GTK_CONTAINER (scrolledwindow2), select_host_dialog->tree_host);
227
228         select_host_dialog->store_host = gtk_tree_store_new(1, G_TYPE_STRING);
229         gtk_tree_view_set_model(GTK_TREE_VIEW(select_host_dialog->tree_host), GTK_TREE_MODEL(select_host_dialog->store_host));
230         g_object_unref(select_host_dialog->store_host); 
231
232         dialog_action_area2 = GTK_DIALOG (select_host_dialog)->action_area;
233         gtk_widget_show (dialog_action_area2);
234         gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area2), GTK_BUTTONBOX_END);
235
236         cancelbutton2 = gtk_button_new_from_stock ("gtk-cancel");
237         gtk_widget_show (cancelbutton2);
238         gtk_dialog_add_action_widget (GTK_DIALOG (select_host_dialog), cancelbutton2, GTK_RESPONSE_CANCEL);
239         GTK_WIDGET_SET_FLAGS (cancelbutton2, GTK_CAN_DEFAULT);
240
241         okbutton2 = gtk_button_new_from_stock ("gtk-ok");
242         gtk_widget_show (okbutton2);
243         gtk_dialog_add_action_widget (GTK_DIALOG (select_host_dialog), okbutton2, GTK_RESPONSE_OK);
244         GTK_WIDGET_SET_FLAGS (okbutton2, GTK_CAN_DEFAULT);
245 }
246
247 GType gtk_select_host_dialog_get_type (void)
248 {
249         static GType mytype = 0;
250
251         if (!mytype)
252         {
253                 static const GTypeInfo myinfo =
254                 {
255                         sizeof (GtkSelectHostDialogClass),
256                         NULL,
257                         NULL,
258                         NULL,
259                         NULL,
260                         NULL,
261                         sizeof(GtkSelectHostDialog),
262                         0,
263                         (GInstanceInitFunc) gtk_select_host_dialog_init,
264                 };
265
266                 mytype = g_type_register_static (GTK_TYPE_DIALOG,
267                                                                                  "GtkSelectHostDialog", &myinfo, 0);
268         }
269
270         return mytype;
271 }
272                                                                                                                              
273 GtkWidget *gtk_select_host_dialog_new (struct sam_pipe *sam_pipe, BOOL nocredentials)
274 {
275         return GTK_WIDGET ( gtk_type_new (gtk_select_host_dialog_get_type ()));
276 }