r4302: fixed all of the annoying gtk warnings. The code all seems to still work, but
[samba.git] / source4 / gtk / tools / gwsam.c
1 /* 
2    Unix SMB/CIFS implementation.
3    GTK+ SAM frontend
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 "dynconfig.h"
24 #include "librpc/gen_ndr/ndr_samr.h"
25 #include "gtk/common/select.h"
26 #include "gtk/common/gtk-smb.h"
27
28 struct policy_handle sam_handle;
29 struct dcerpc_pipe *sam_pipe = NULL;
30 struct policy_handle domain_handle;
31 GtkWidget *mainwin;
32 GtkWidget *seldomain;
33 GtkWidget *mnu_disconnect;
34
35 void update_grouplist(void)
36 {
37         if(!sam_pipe) return;
38         //FIXME
39 }
40
41 void update_userlist(void)
42 {
43         NTSTATUS status;
44         struct samr_EnumDomainUsers r;
45         uint32_t resume_handle=0;
46         int i;
47         TALLOC_CTX *mem_ctx;
48
49         if(!sam_pipe) return;
50
51         mem_ctx = talloc_init("update_userlist");
52         r.in.domain_handle = &domain_handle;
53         r.in.resume_handle = &resume_handle;
54         r.in.acct_flags = 0;
55         r.in.max_size = (uint32_t)-1;
56         r.out.resume_handle = &resume_handle;
57
58         status = dcerpc_samr_EnumDomainUsers(sam_pipe, mem_ctx, &r);
59         if (!NT_STATUS_IS_OK(status)) {
60                 gtk_show_ntstatus(mainwin, status);
61                 talloc_destroy(mem_ctx);
62                 return;
63         }
64
65         if (!r.out.sam || r.out.sam->count == 0) {
66                 talloc_destroy(mem_ctx);
67                 return;
68         }
69
70         for (i=0;i<r.out.sam->count;i++) {
71                 printf("Found: %s\n", r.out.sam->entries[i].name.string);
72                 /* FIXME: Query user info */
73
74                 //              if (!test_OpenUser(sam_pipe, mem_ctx, &sam_handle, r.out.sam->entries[i].idx)) {
75                 //                      ret = False;
76                 //              }
77         }
78         talloc_destroy(mem_ctx);
79 }
80
81 void
82 on_new1_activate                       (GtkMenuItem     *menuitem,
83                                                                                 gpointer         user_data)
84 {
85
86 }
87
88 void
89 on_select_domain_activate                       (GtkMenuItem     *menuitem,
90                                                                                                  gpointer         user_data)
91 {
92         GtkSelectDomainDialog *d;
93         gint result;
94         d = GTK_SELECT_DOMAIN_DIALOG(gtk_select_domain_dialog_new(sam_pipe));
95         result = gtk_dialog_run(GTK_DIALOG(d));
96         switch(result) {
97         case GTK_RESPONSE_OK:
98                 break;
99         default:
100                 gtk_widget_destroy(GTK_WIDGET(d));
101                 return;
102         }
103         domain_handle = gtk_select_domain_dialog_get_handle(d);
104
105         update_userlist();
106         update_grouplist();
107
108         gtk_widget_destroy(GTK_WIDGET(d));
109 }
110
111 static void connect_sam(void)
112 {
113         GtkRpcBindingDialog *d;
114         NTSTATUS status;
115         struct samr_Connect r;
116         TALLOC_CTX *mem_ctx;
117         gint result;
118
119         d = GTK_RPC_BINDING_DIALOG(gtk_rpc_binding_dialog_new(FALSE, NULL));
120         result = gtk_dialog_run(GTK_DIALOG(d));
121         switch(result) {
122         case GTK_RESPONSE_ACCEPT:
123                 break;
124         default:
125                 gtk_widget_destroy(GTK_WIDGET(d));
126                 return;
127         }
128
129         mem_ctx = talloc_init("gwsam_connect");
130         /* If connected, get list of jobs */
131         status = dcerpc_pipe_connect_b(&sam_pipe,
132                                         gtk_rpc_binding_dialog_get_binding(d, mem_ctx),
133                                         DCERPC_SAMR_UUID, DCERPC_SAMR_VERSION,
134                                         gtk_rpc_binding_dialog_get_userdomain(d),
135                                         gtk_rpc_binding_dialog_get_username(d),
136                                         gtk_rpc_binding_dialog_get_password(d));
137
138         if(!NT_STATUS_IS_OK(status)) {
139                 gtk_show_ntstatus(mainwin, status);
140                 sam_pipe = NULL;
141                 gtk_widget_destroy(GTK_WIDGET(d));
142                 talloc_destroy(mem_ctx);
143                 return;
144         }
145
146         r.in.system_name = 0;
147         r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
148         r.out.connect_handle = &sam_handle;
149
150         status = dcerpc_samr_Connect(sam_pipe, mem_ctx, &r);
151         if (!NT_STATUS_IS_OK(status)) {
152                 gtk_show_ntstatus(mainwin, status);
153                 sam_pipe = NULL;
154                 gtk_widget_destroy(GTK_WIDGET(d));
155                 talloc_destroy(mem_ctx);
156                 return;
157         }
158
159         gtk_widget_set_sensitive (seldomain, TRUE);
160         gtk_widget_set_sensitive (mnu_disconnect, TRUE);
161         gtk_window_set_title (GTK_WINDOW (mainwin), talloc_asprintf(mem_ctx, "User Manager - Connected to %s", gtk_rpc_binding_dialog_get_host(d)));
162         gtk_widget_destroy(GTK_WIDGET(d));
163         talloc_destroy(mem_ctx);
164
165 }
166
167 static void on_connect_activate (GtkMenuItem *menuitem, gpointer user_data)
168 {
169         connect_sam();
170 }
171
172 static void on_disconnect_activate (GtkMenuItem *menuitem, gpointer user_data)
173 {
174         gtk_widget_set_sensitive (mnu_disconnect, FALSE);
175         gtk_window_set_title (GTK_WINDOW (mainwin), "User Manager");
176 }
177
178 void
179 on_quit_activate                      (GtkMenuItem     *menuitem,
180                                                                            gpointer         user_data)
181 {
182         if(sam_pipe)dcerpc_pipe_close(sam_pipe);
183         gtk_main_quit();
184 }
185
186
187 void
188 on_account_activate                    (GtkMenuItem     *menuitem,
189                                                                                 gpointer         user_data)
190 {
191         //FIXME
192 }
193
194
195 void
196 on_user_rights_activate                (GtkMenuItem     *menuitem,
197                                                                                 gpointer         user_data)
198 {
199         //FIXME
200 }
201
202
203 void
204 on_audit_activate                      (GtkMenuItem     *menuitem,
205                                                                                 gpointer         user_data)
206 {
207         //FIXME
208 }
209
210
211 void
212 on_trust_relations_activate            (GtkMenuItem     *menuitem,
213                                                                                 gpointer         user_data)
214 {
215         //FIXME
216 }
217
218
219 void
220 on_refresh_activate                    (GtkMenuItem     *menuitem,
221                                                                                 gpointer         user_data)
222 {
223         update_userlist();
224         update_grouplist();
225 }
226
227
228 void
229 on_about_activate                     (GtkMenuItem     *menuitem,
230                                                                            gpointer         user_data)
231 {
232         GtkDialog *aboutwin = GTK_DIALOG(create_gtk_samba_about_dialog("gwsam"));
233         gtk_dialog_run(aboutwin);
234         gtk_widget_destroy(GTK_WIDGET(aboutwin));
235 }
236
237 GtkWidget*
238 create_mainwindow (void)
239 {
240         GtkWidget *vbox1;
241         GtkWidget *mnu_connect;
242         GtkWidget *menubar;
243         GtkWidget *menuitem1;
244         GtkWidget *menuitem1_menu;
245         GtkWidget *new1;
246         GtkWidget *separatormenuitem1;
247         GtkWidget *quit;
248         GtkWidget *policies;
249         GtkWidget *policies_menu;
250         GtkWidget *account;
251         GtkWidget *user_rights;
252         GtkWidget *audit;
253         GtkWidget *separator1;
254         GtkWidget *trust_relations;
255         GtkWidget *menuitem3;
256         GtkWidget *menuitem3_menu;
257         GtkWidget *refresh;
258         GtkWidget *menuitem4;
259         GtkWidget *menuitem4_menu;
260         GtkWidget *about;
261         GtkWidget *vpaned;
262         GtkWidget *scrolledwindow1;
263         GtkWidget *user_list;
264         GtkWidget *scrolledwindow2;
265         GtkWidget *group_list;
266         GtkWidget *statusbar;
267         GtkAccelGroup *accel_group;
268
269         accel_group = gtk_accel_group_new ();
270
271         mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
272         gtk_window_set_default_size (GTK_WINDOW (mainwin), 642, 562);
273         gtk_window_set_title (GTK_WINDOW (mainwin), "User Manager");
274
275         vbox1 = gtk_vbox_new (FALSE, 0);
276         gtk_container_add (GTK_CONTAINER (mainwin), vbox1);
277
278         menubar = gtk_menu_bar_new ();
279         gtk_box_pack_start (GTK_BOX (vbox1), menubar, FALSE, FALSE, 0);
280
281         menuitem1 = gtk_menu_item_new_with_mnemonic ("_File");
282         gtk_container_add (GTK_CONTAINER (menubar), menuitem1);
283
284         menuitem1_menu = gtk_menu_new ();
285         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem1), menuitem1_menu);
286
287         mnu_connect = gtk_menu_item_new_with_mnemonic ("_Connect");
288         gtk_container_add (GTK_CONTAINER (menuitem1_menu), mnu_connect);
289
290         mnu_disconnect = gtk_menu_item_new_with_mnemonic ("_Disconnect");
291         gtk_widget_set_sensitive (mnu_disconnect, FALSE);
292         gtk_container_add (GTK_CONTAINER (menuitem1_menu), mnu_disconnect);
293
294         seldomain = gtk_menu_item_new_with_mnemonic("_Select Domain");
295         gtk_widget_set_sensitive (seldomain, FALSE);
296         gtk_container_add (GTK_CONTAINER (menuitem1_menu), seldomain);
297
298         separatormenuitem1 = gtk_separator_menu_item_new ();
299         gtk_container_add (GTK_CONTAINER (menuitem1_menu), separatormenuitem1);
300         gtk_widget_set_sensitive (separatormenuitem1, FALSE);
301
302         quit = gtk_image_menu_item_new_from_stock ("gtk-quit", accel_group);
303         gtk_container_add (GTK_CONTAINER (menuitem1_menu), quit);
304
305         menuitem1 = gtk_menu_item_new_with_mnemonic ("_User");
306         gtk_container_add (GTK_CONTAINER (menubar), menuitem1);
307         gtk_widget_set_sensitive (menuitem1, FALSE);
308
309         menuitem1_menu = gtk_menu_new ();
310         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem1), menuitem1_menu);
311
312         new1 = gtk_image_menu_item_new_from_stock ("gtk-new", accel_group);
313         gtk_container_add (GTK_CONTAINER (menuitem1_menu), new1);
314
315
316
317         policies = gtk_menu_item_new_with_mnemonic ("_Policies");
318         gtk_container_add (GTK_CONTAINER (menubar), policies);
319         gtk_widget_set_sensitive (policies, FALSE);
320
321         policies_menu = gtk_menu_new ();
322         gtk_menu_item_set_submenu (GTK_MENU_ITEM (policies), policies_menu);
323
324         account = gtk_menu_item_new_with_mnemonic ("_Account...");
325         gtk_container_add (GTK_CONTAINER (policies_menu), account);
326
327         user_rights = gtk_menu_item_new_with_mnemonic ("_User Rights...");
328         gtk_container_add (GTK_CONTAINER (policies_menu), user_rights);
329
330         audit = gtk_menu_item_new_with_mnemonic ("A_udit...");
331         gtk_container_add (GTK_CONTAINER (policies_menu), audit);
332
333         separator1 = gtk_separator_menu_item_new ();
334         gtk_container_add (GTK_CONTAINER (policies_menu), separator1);
335         gtk_widget_set_sensitive (separator1, FALSE);
336
337         trust_relations = gtk_menu_item_new_with_mnemonic ("_Trust relations");
338         gtk_container_add (GTK_CONTAINER (policies_menu), trust_relations);
339
340         menuitem3 = gtk_menu_item_new_with_mnemonic ("_View");
341         gtk_container_add (GTK_CONTAINER (menubar), menuitem3);
342
343         menuitem3_menu = gtk_menu_new ();
344         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem3), menuitem3_menu);
345
346         refresh = gtk_image_menu_item_new_from_stock ("gtk-refresh", accel_group);
347         gtk_container_add (GTK_CONTAINER (menuitem3_menu), refresh);
348         gtk_widget_set_sensitive (refresh, FALSE);
349
350         menuitem4 = gtk_menu_item_new_with_mnemonic ("_Help");
351         gtk_container_add (GTK_CONTAINER (menubar), menuitem4);
352
353         menuitem4_menu = gtk_menu_new ();
354         gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem4), menuitem4_menu);
355
356         about = gtk_menu_item_new_with_mnemonic ("_About");
357         gtk_container_add (GTK_CONTAINER (menuitem4_menu), about);
358
359         vpaned = gtk_vpaned_new ();
360         gtk_box_pack_start (GTK_BOX (vbox1), vpaned, TRUE, TRUE, 0);
361
362         scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
363         gtk_paned_pack1 (GTK_PANED (vpaned), scrolledwindow1, FALSE, TRUE);
364
365         user_list = gtk_tree_view_new ();
366         gtk_container_add (GTK_CONTAINER (scrolledwindow1), user_list);
367
368         scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
369         gtk_paned_pack2 (GTK_PANED (vpaned), scrolledwindow2, TRUE, TRUE);
370
371         group_list = gtk_tree_view_new ();
372         gtk_container_add (GTK_CONTAINER (scrolledwindow2), group_list);
373
374         statusbar = gtk_statusbar_new ();
375         gtk_box_pack_start (GTK_BOX (vbox1), statusbar, FALSE, FALSE, 0);
376
377         g_signal_connect ((gpointer) new1, "activate",
378                                           G_CALLBACK (on_new1_activate),
379                                           NULL);
380         g_signal_connect ((gpointer) seldomain, "activate",
381                                           G_CALLBACK (on_select_domain_activate),
382                                           NULL);
383         g_signal_connect ((gpointer) mnu_connect, "activate",
384                                           G_CALLBACK (on_connect_activate),
385                                           NULL);
386         g_signal_connect ((gpointer) mnu_disconnect, "activate",
387                                           G_CALLBACK (on_disconnect_activate),
388                                           NULL);
389         g_signal_connect ((gpointer) quit, "activate",
390                                           G_CALLBACK (on_quit_activate),
391                                           NULL);
392         g_signal_connect ((gpointer) account, "activate",
393                                           G_CALLBACK (on_account_activate),
394                                           NULL);
395         g_signal_connect ((gpointer) user_rights, "activate",
396                                           G_CALLBACK (on_user_rights_activate),
397                                           NULL);
398         g_signal_connect ((gpointer) audit, "activate",
399                                           G_CALLBACK (on_audit_activate),
400                                           NULL);
401         g_signal_connect ((gpointer) trust_relations, "activate",
402                                           G_CALLBACK (on_trust_relations_activate),
403                                           NULL);
404         g_signal_connect ((gpointer) refresh, "activate",
405                                           G_CALLBACK (on_refresh_activate),
406                                           NULL);
407         g_signal_connect ((gpointer) about, "activate",
408                                           G_CALLBACK (on_about_activate),
409                                           NULL);
410
411         gtk_window_add_accel_group (GTK_WINDOW (mainwin), accel_group);
412
413         return mainwin;
414 }
415
416
417
418  int main(int argc, char **argv)
419 {
420         gwsam_init_subsystems;
421         lp_load(dyn_CONFIGFILE,True,False,False);
422         load_interfaces();
423         setup_logging("gwsam", True);
424
425         gtk_init(&argc, &argv);
426         mainwin = create_mainwindow();
427         connect_sam();
428         gtk_widget_show_all(mainwin);
429         gtk_main();
430
431         return 0;
432 }