2 Unix SMB/CIFS implementation.
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.
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
;
33 static GtkWidget
*mnu_disconnect
;
35 static void update_grouplist(void)
41 static void update_userlist(void)
44 struct samr_EnumDomainUsers r
;
45 uint32_t resume_handle
=0;
51 mem_ctx
= talloc_init("update_userlist");
52 r
.in
.domain_handle
= &domain_handle
;
53 r
.in
.resume_handle
= &resume_handle
;
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
);
65 if (!r
.out
.sam
|| r
.out
.sam
->count
== 0) {
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)) {
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
;
90 d
= GTK_SELECT_DOMAIN_DIALOG(gtk_select_domain_dialog_new(sam_pipe
));
91 result
= gtk_dialog_run(GTK_DIALOG(d
));
96 gtk_widget_destroy(GTK_WIDGET(d
));
99 domain_handle
= gtk_select_domain_dialog_get_handle(d
);
104 gtk_widget_destroy(GTK_WIDGET(d
));
107 static void connect_sam(void)
109 GtkRpcBindingDialog
*d
;
111 struct samr_Connect r
;
112 struct cli_credentials
*cred
;
116 d
= GTK_RPC_BINDING_DIALOG(gtk_rpc_binding_dialog_new(NULL
));
117 result
= gtk_dialog_run(GTK_DIALOG(d
));
119 case GTK_RESPONSE_ACCEPT
:
122 gtk_widget_destroy(GTK_WIDGET(d
));
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
);
139 gtk_widget_destroy(GTK_WIDGET(d
));
140 talloc_free(mem_ctx
);
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
);
152 gtk_widget_destroy(GTK_WIDGET(d
));
153 talloc_free(mem_ctx
);
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
)
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
);
185 static void on_account_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
191 static void on_user_rights_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
197 static void on_audit_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
203 static void on_trust_relations_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
209 static void on_refresh_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
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)
226 GtkWidget
*mnu_connect
;
228 GtkWidget
*menuitem1
;
229 GtkWidget
*menuitem1_menu
;
231 GtkWidget
*separatormenuitem1
;
234 GtkWidget
*policies_menu
;
236 GtkWidget
*user_rights
;
238 GtkWidget
*separator1
;
239 GtkWidget
*trust_relations
;
240 GtkWidget
*menuitem3
;
241 GtkWidget
*menuitem3_menu
;
243 GtkWidget
*menuitem4
;
244 GtkWidget
*menuitem4_menu
;
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
),
365 g_signal_connect ((gpointer
) seldomain
, "activate",
366 G_CALLBACK (on_select_domain_activate
),
368 g_signal_connect ((gpointer
) mnu_connect
, "activate",
369 G_CALLBACK (on_connect_activate
),
371 g_signal_connect ((gpointer
) mnu_disconnect
, "activate",
372 G_CALLBACK (on_disconnect_activate
),
374 g_signal_connect ((gpointer
) quit
, "activate",
375 G_CALLBACK (on_quit_activate
),
377 g_signal_connect ((gpointer
) account
, "activate",
378 G_CALLBACK (on_account_activate
),
380 g_signal_connect ((gpointer
) user_rights
, "activate",
381 G_CALLBACK (on_user_rights_activate
),
383 g_signal_connect ((gpointer
) audit
, "activate",
384 G_CALLBACK (on_audit_activate
),
386 g_signal_connect ((gpointer
) trust_relations
, "activate",
387 G_CALLBACK (on_trust_relations_activate
),
389 g_signal_connect ((gpointer
) refresh
, "activate",
390 G_CALLBACK (on_refresh_activate
),
392 g_signal_connect ((gpointer
) about
, "activate",
393 G_CALLBACK (on_about_activate
),
396 gtk_window_add_accel_group (GTK_WINDOW (mainwin
), accel_group
);
401 int main(int argc
, char **argv
)
404 setup_logging(argv
[0], DEBUG_STDERR
);
406 gtk_init(&argc
, &argv
);
407 mainwin
= create_mainwindow();
409 gtk_widget_show_all(mainwin
);
411 return gtk_event_loop();