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