r14470: Remove some unnecessary headers.
[Samba.git] / source / gtk / tools / gwsam.c
blob5f274e622b029c2c5d1cc8d41a621f362e93614f
1 /*
2 Unix SMB/CIFS implementation.
3 GTK+ SAM frontend
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_c.h"
24 #include "gtk/common/select.h"
25 #include "gtk/common/gtk-smb.h"
26 #include "auth/credentials/credentials.h"
28 struct policy_handle sam_handle;
29 struct dcerpc_pipe *sam_pipe = NULL;
30 static struct policy_handle domain_handle;
31 GtkWidget *mainwin;
32 GtkWidget *seldomain;
33 static GtkWidget *mnu_disconnect;
35 static void update_grouplist(void)
37 if(!sam_pipe) return;
38 //FIXME
41 static void update_userlist(void)
43 NTSTATUS status;
44 struct samr_EnumDomainUsers r;
45 uint32_t resume_handle=0;
46 int i;
47 TALLOC_CTX *mem_ctx;
49 if(!sam_pipe) return;
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;
58 status = dcerpc_samr_EnumDomainUsers(sam_pipe, mem_ctx, &r);
59 if (!NT_STATUS_IS_OK(status)) {
60 gtk_show_ntstatus(mainwin, "While enumerating domain users", status);
61 talloc_free(mem_ctx);
62 return;
65 if (!r.out.sam || r.out.sam->count == 0) {
66 talloc_free(mem_ctx);
67 return;
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 */
74 // if (!test_OpenUser(sam_pipe, mem_ctx, &sam_handle, r.out.sam->entries[i].idx)) {
75 // ret = False;
76 // }
78 talloc_free(mem_ctx);
81 static void on_new1_activate(GtkMenuItem *menuitem, gpointer user_data)
86 static void on_select_domain_activate(GtkMenuItem *menuitem, gpointer user_data)
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_OK:
94 break;
95 default:
96 gtk_widget_destroy(GTK_WIDGET(d));
97 return;
99 domain_handle = gtk_select_domain_dialog_get_handle(d);
101 update_userlist();
102 update_grouplist();
104 gtk_widget_destroy(GTK_WIDGET(d));
107 static void connect_sam(void)
109 GtkRpcBindingDialog *d;
110 NTSTATUS status;
111 struct samr_Connect r;
112 struct cli_credentials *cred;
113 TALLOC_CTX *mem_ctx;
114 gint result;
116 d = GTK_RPC_BINDING_DIALOG(gtk_rpc_binding_dialog_new(NULL));
117 result = gtk_dialog_run(GTK_DIALOG(d));
118 switch(result) {
119 case GTK_RESPONSE_ACCEPT:
120 break;
121 default:
122 gtk_widget_destroy(GTK_WIDGET(d));
123 return;
126 mem_ctx = talloc_init("gwsam_connect");
127 cred = cli_credentials_init(mem_ctx);
128 cli_credentials_guess(cred);
129 cli_credentials_set_gtk_callbacks(cred);
131 /* If connected, get list of jobs */
132 status = dcerpc_pipe_connect_b(mem_ctx, &sam_pipe,
133 gtk_rpc_binding_dialog_get_binding(d, mem_ctx),
134 &dcerpc_table_samr, cred, NULL);
136 if(!NT_STATUS_IS_OK(status)) {
137 gtk_show_ntstatus(mainwin, "While connecting to SAMR interface", status);
138 sam_pipe = NULL;
139 gtk_widget_destroy(GTK_WIDGET(d));
140 talloc_free(mem_ctx);
141 return;
144 r.in.system_name = 0;
145 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
146 r.out.connect_handle = &sam_handle;
148 status = dcerpc_samr_Connect(sam_pipe, mem_ctx, &r);
149 if (!NT_STATUS_IS_OK(status)) {
150 gtk_show_ntstatus(mainwin, "While running connect on SAMR", status);
151 sam_pipe = NULL;
152 gtk_widget_destroy(GTK_WIDGET(d));
153 talloc_free(mem_ctx);
154 return;
157 gtk_widget_set_sensitive (seldomain, TRUE);
158 gtk_widget_set_sensitive (mnu_disconnect, TRUE);
159 gtk_window_set_title (GTK_WINDOW (mainwin), talloc_asprintf(mem_ctx, "User Manager - Connected to %s", gtk_rpc_binding_dialog_get_host(d)));
160 gtk_widget_destroy(GTK_WIDGET(d));
162 sam_pipe = talloc_reference(talloc_autofree_context(), sam_pipe);
163 talloc_free(mem_ctx);
167 static void on_connect_activate (GtkMenuItem *menuitem, gpointer user_data)
169 connect_sam();
172 static void on_disconnect_activate (GtkMenuItem *menuitem, gpointer user_data)
174 gtk_widget_set_sensitive (mnu_disconnect, FALSE);
175 gtk_window_set_title (GTK_WINDOW (mainwin), "User Manager");
178 static void on_quit_activate (GtkMenuItem *menuitem, gpointer user_data)
180 talloc_free(sam_pipe);
182 gtk_main_quit();
185 static void on_account_activate(GtkMenuItem *menuitem, gpointer user_data)
187 //FIXME
191 static void on_user_rights_activate(GtkMenuItem *menuitem, gpointer user_data)
193 //FIXME
197 static void on_audit_activate(GtkMenuItem *menuitem, gpointer user_data)
199 //FIXME
203 static void on_trust_relations_activate(GtkMenuItem *menuitem, gpointer user_data)
205 //FIXME
209 static void on_refresh_activate(GtkMenuItem *menuitem, gpointer user_data)
211 update_userlist();
212 update_grouplist();
216 static void on_about_activate(GtkMenuItem *menuitem, gpointer user_data)
218 GtkDialog *aboutwin = GTK_DIALOG(create_gtk_samba_about_dialog("gwsam"));
219 gtk_dialog_run(aboutwin);
220 gtk_widget_destroy(GTK_WIDGET(aboutwin));
223 static GtkWidget* create_mainwindow (void)
225 GtkWidget *vbox1;
226 GtkWidget *mnu_connect;
227 GtkWidget *menubar;
228 GtkWidget *menuitem1;
229 GtkWidget *menuitem1_menu;
230 GtkWidget *new1;
231 GtkWidget *separatormenuitem1;
232 GtkWidget *quit;
233 GtkWidget *policies;
234 GtkWidget *policies_menu;
235 GtkWidget *account;
236 GtkWidget *user_rights;
237 GtkWidget *audit;
238 GtkWidget *separator1;
239 GtkWidget *trust_relations;
240 GtkWidget *menuitem3;
241 GtkWidget *menuitem3_menu;
242 GtkWidget *refresh;
243 GtkWidget *menuitem4;
244 GtkWidget *menuitem4_menu;
245 GtkWidget *about;
246 GtkWidget *vpaned;
247 GtkWidget *scrolledwindow1;
248 GtkWidget *user_list;
249 GtkWidget *scrolledwindow2;
250 GtkWidget *group_list;
251 GtkWidget *statusbar;
252 GtkAccelGroup *accel_group;
254 accel_group = gtk_accel_group_new ();
256 mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
257 gtk_window_set_default_size (GTK_WINDOW (mainwin), 642, 562);
258 gtk_window_set_title (GTK_WINDOW (mainwin), "User Manager");
260 vbox1 = gtk_vbox_new (FALSE, 0);
261 gtk_container_add (GTK_CONTAINER (mainwin), vbox1);
263 menubar = gtk_menu_bar_new ();
264 gtk_box_pack_start (GTK_BOX (vbox1), menubar, FALSE, FALSE, 0);
266 menuitem1 = gtk_menu_item_new_with_mnemonic ("_File");
267 gtk_container_add (GTK_CONTAINER (menubar), menuitem1);
269 menuitem1_menu = gtk_menu_new ();
270 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem1), menuitem1_menu);
272 mnu_connect = gtk_menu_item_new_with_mnemonic ("_Connect");
273 gtk_container_add (GTK_CONTAINER (menuitem1_menu), mnu_connect);
275 mnu_disconnect = gtk_menu_item_new_with_mnemonic ("_Disconnect");
276 gtk_widget_set_sensitive (mnu_disconnect, FALSE);
277 gtk_container_add (GTK_CONTAINER (menuitem1_menu), mnu_disconnect);
279 seldomain = gtk_menu_item_new_with_mnemonic("_Select Domain");
280 gtk_widget_set_sensitive (seldomain, FALSE);
281 gtk_container_add (GTK_CONTAINER (menuitem1_menu), seldomain);
283 separatormenuitem1 = gtk_separator_menu_item_new ();
284 gtk_container_add (GTK_CONTAINER (menuitem1_menu), separatormenuitem1);
285 gtk_widget_set_sensitive (separatormenuitem1, FALSE);
287 quit = gtk_image_menu_item_new_from_stock ("gtk-quit", accel_group);
288 gtk_container_add (GTK_CONTAINER (menuitem1_menu), quit);
290 menuitem1 = gtk_menu_item_new_with_mnemonic ("_User");
291 gtk_container_add (GTK_CONTAINER (menubar), menuitem1);
292 gtk_widget_set_sensitive (menuitem1, FALSE);
294 menuitem1_menu = gtk_menu_new ();
295 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem1), menuitem1_menu);
297 new1 = gtk_image_menu_item_new_from_stock ("gtk-new", accel_group);
298 gtk_container_add (GTK_CONTAINER (menuitem1_menu), new1);
302 policies = gtk_menu_item_new_with_mnemonic ("_Policies");
303 gtk_container_add (GTK_CONTAINER (menubar), policies);
304 gtk_widget_set_sensitive (policies, FALSE);
306 policies_menu = gtk_menu_new ();
307 gtk_menu_item_set_submenu (GTK_MENU_ITEM (policies), policies_menu);
309 account = gtk_menu_item_new_with_mnemonic ("_Account...");
310 gtk_container_add (GTK_CONTAINER (policies_menu), account);
312 user_rights = gtk_menu_item_new_with_mnemonic ("_User Rights...");
313 gtk_container_add (GTK_CONTAINER (policies_menu), user_rights);
315 audit = gtk_menu_item_new_with_mnemonic ("A_udit...");
316 gtk_container_add (GTK_CONTAINER (policies_menu), audit);
318 separator1 = gtk_separator_menu_item_new ();
319 gtk_container_add (GTK_CONTAINER (policies_menu), separator1);
320 gtk_widget_set_sensitive (separator1, FALSE);
322 trust_relations = gtk_menu_item_new_with_mnemonic ("_Trust relations");
323 gtk_container_add (GTK_CONTAINER (policies_menu), trust_relations);
325 menuitem3 = gtk_menu_item_new_with_mnemonic ("_View");
326 gtk_container_add (GTK_CONTAINER (menubar), menuitem3);
328 menuitem3_menu = gtk_menu_new ();
329 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem3), menuitem3_menu);
331 refresh = gtk_image_menu_item_new_from_stock ("gtk-refresh", accel_group);
332 gtk_container_add (GTK_CONTAINER (menuitem3_menu), refresh);
333 gtk_widget_set_sensitive (refresh, FALSE);
335 menuitem4 = gtk_menu_item_new_with_mnemonic ("_Help");
336 gtk_container_add (GTK_CONTAINER (menubar), menuitem4);
338 menuitem4_menu = gtk_menu_new ();
339 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem4), menuitem4_menu);
341 about = gtk_menu_item_new_with_mnemonic ("_About");
342 gtk_container_add (GTK_CONTAINER (menuitem4_menu), about);
344 vpaned = gtk_vpaned_new ();
345 gtk_box_pack_start (GTK_BOX (vbox1), vpaned, TRUE, TRUE, 0);
347 scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
348 gtk_paned_pack1 (GTK_PANED (vpaned), scrolledwindow1, FALSE, TRUE);
350 user_list = gtk_tree_view_new ();
351 gtk_container_add (GTK_CONTAINER (scrolledwindow1), user_list);
353 scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
354 gtk_paned_pack2 (GTK_PANED (vpaned), scrolledwindow2, TRUE, TRUE);
356 group_list = gtk_tree_view_new ();
357 gtk_container_add (GTK_CONTAINER (scrolledwindow2), group_list);
359 statusbar = gtk_statusbar_new ();
360 gtk_box_pack_start (GTK_BOX (vbox1), statusbar, FALSE, FALSE, 0);
362 g_signal_connect ((gpointer) new1, "activate",
363 G_CALLBACK (on_new1_activate),
364 NULL);
365 g_signal_connect ((gpointer) seldomain, "activate",
366 G_CALLBACK (on_select_domain_activate),
367 NULL);
368 g_signal_connect ((gpointer) mnu_connect, "activate",
369 G_CALLBACK (on_connect_activate),
370 NULL);
371 g_signal_connect ((gpointer) mnu_disconnect, "activate",
372 G_CALLBACK (on_disconnect_activate),
373 NULL);
374 g_signal_connect ((gpointer) quit, "activate",
375 G_CALLBACK (on_quit_activate),
376 NULL);
377 g_signal_connect ((gpointer) account, "activate",
378 G_CALLBACK (on_account_activate),
379 NULL);
380 g_signal_connect ((gpointer) user_rights, "activate",
381 G_CALLBACK (on_user_rights_activate),
382 NULL);
383 g_signal_connect ((gpointer) audit, "activate",
384 G_CALLBACK (on_audit_activate),
385 NULL);
386 g_signal_connect ((gpointer) trust_relations, "activate",
387 G_CALLBACK (on_trust_relations_activate),
388 NULL);
389 g_signal_connect ((gpointer) refresh, "activate",
390 G_CALLBACK (on_refresh_activate),
391 NULL);
392 g_signal_connect ((gpointer) about, "activate",
393 G_CALLBACK (on_about_activate),
394 NULL);
396 gtk_window_add_accel_group (GTK_WINDOW (mainwin), accel_group);
398 return mainwin;
401 int main(int argc, char **argv)
403 lp_load();
404 setup_logging(argv[0], DEBUG_STDERR);
406 gtk_init(&argc, &argv);
407 mainwin = create_mainwindow();
408 connect_sam();
409 gtk_widget_show_all(mainwin);
411 return gtk_event_loop();