summaryrefslogtreecommitdiff
path: root/source4/gtk/tools/gwsam.c
blob: 55e11471e23f651173e28b89ac3092cecc40df86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/* 
   Unix SMB/CIFS implementation.
   GTK+ SAM frontend
   
   Copyright (C) Jelmer Vernooij 2004

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "includes.h"
#include "librpc/gen_ndr/ndr_samr.h"
#include "gtk/common/select.h"
#include "gtk/common/gtk-smb.h"

struct policy_handle sam_handle;
struct dcerpc_pipe *sam_pipe = NULL;
static struct policy_handle domain_handle;
GtkWidget *mainwin;
GtkWidget *seldomain;
static GtkWidget *mnu_disconnect;

static void update_grouplist(void)
{
	if(!sam_pipe) return;
	//FIXME
}

static void update_userlist(void)
{
	NTSTATUS status;
	struct samr_EnumDomainUsers r;
	uint32_t resume_handle=0;
	int i;
	TALLOC_CTX *mem_ctx;

	if(!sam_pipe) return;

	mem_ctx = talloc_init("update_userlist");
	r.in.domain_handle = &domain_handle;
	r.in.resume_handle = &resume_handle;
	r.in.acct_flags = 0;
	r.in.max_size = (uint32_t)-1;
	r.out.resume_handle = &resume_handle;

	status = dcerpc_samr_EnumDomainUsers(sam_pipe, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		gtk_show_ntstatus(mainwin, "While enumerating domain users", status);
		talloc_free(mem_ctx);
		return;
	}

	if (!r.out.sam || r.out.sam->count == 0) {
		talloc_free(mem_ctx);
		return;
	}

	for (i=0;i<r.out.sam->count;i++) {
		printf("Found: %s\n", r.out.sam->entries[i].name.string);
		/* FIXME: Query user info */

		//		if (!test_OpenUser(sam_pipe, mem_ctx, &sam_handle, r.out.sam->entries[i].idx)) {
		//			ret = False;
		//		}
	}
	talloc_free(mem_ctx);
}

static void on_new1_activate(GtkMenuItem *menuitem, gpointer user_data)
{

}

static void on_select_domain_activate(GtkMenuItem *menuitem, gpointer user_data)
{
	GtkSelectDomainDialog *d;
	gint result;
	d = GTK_SELECT_DOMAIN_DIALOG(gtk_select_domain_dialog_new(sam_pipe));
	result = gtk_dialog_run(GTK_DIALOG(d));
	switch(result) {
	case GTK_RESPONSE_OK:
		break;
	default:
		gtk_widget_destroy(GTK_WIDGET(d));
		return;
	}
	domain_handle = gtk_select_domain_dialog_get_handle(d);

	update_userlist();
	update_grouplist();

	gtk_widget_destroy(GTK_WIDGET(d));
}

static void connect_sam(void)
{
	GtkRpcBindingDialog *d;
	NTSTATUS status;
	struct samr_Connect r;
	struct cli_credentials *cred;
	TALLOC_CTX *mem_ctx;
	gint result;

	d = GTK_RPC_BINDING_DIALOG(gtk_rpc_binding_dialog_new(NULL));
	result = gtk_dialog_run(GTK_DIALOG(d));
	switch(result) {
	case GTK_RESPONSE_ACCEPT:
		break;
	default:
		gtk_widget_destroy(GTK_WIDGET(d));
		return;
	}

	mem_ctx = talloc_init("gwsam_connect");
	cred = cli_credentials_init(mem_ctx);
	cli_credentials_guess(cred);
	cli_credentials_set_gtk_callbacks(cred);

	/* If connected, get list of jobs */
	status = dcerpc_pipe_connect_b(mem_ctx, &sam_pipe,
				       gtk_rpc_binding_dialog_get_binding(d, mem_ctx),
				       &dcerpc_table_samr, cred, NULL);

	if(!NT_STATUS_IS_OK(status)) {
		gtk_show_ntstatus(mainwin, "While connecting to SAMR interface", status);
		sam_pipe = NULL;
		gtk_widget_destroy(GTK_WIDGET(d));
		talloc_free(mem_ctx);
		return;
	}

	r.in.system_name = 0;
	r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
	r.out.connect_handle = &sam_handle;

	status = dcerpc_samr_Connect(sam_pipe, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		gtk_show_ntstatus(mainwin, "While running connect on SAMR", status);
		sam_pipe = NULL;
		gtk_widget_destroy(GTK_WIDGET(d));
		talloc_free(mem_ctx);
		return;
	}

	gtk_widget_set_sensitive (seldomain, TRUE);
	gtk_widget_set_sensitive (mnu_disconnect, TRUE);
	gtk_window_set_title (GTK_WINDOW (mainwin), talloc_asprintf(mem_ctx, "User Manager - Connected to %s", gtk_rpc_binding_dialog_get_host(d)));
	gtk_widget_destroy(GTK_WIDGET(d));

	sam_pipe = talloc_reference(talloc_autofree_context(), sam_pipe);
	talloc_free(mem_ctx);

}

static void on_connect_activate (GtkMenuItem *menuitem, gpointer user_data)
{
	connect_sam();
}

static void on_disconnect_activate (GtkMenuItem *menuitem, gpointer user_data)
{
	gtk_widget_set_sensitive (mnu_disconnect, FALSE);
	gtk_window_set_title (GTK_WINDOW (mainwin), "User Manager");
}

static void on_quit_activate (GtkMenuItem *menuitem, gpointer user_data)
{
	talloc_free(sam_pipe);

	gtk_main_quit();
}

static void on_account_activate(GtkMenuItem *menuitem, gpointer user_data)
{
	//FIXME
}


static void on_user_rights_activate(GtkMenuItem *menuitem, gpointer user_data)
{
	//FIXME
}


static void on_audit_activate(GtkMenuItem *menuitem, gpointer user_data)
{
	//FIXME
}


static void on_trust_relations_activate(GtkMenuItem *menuitem, gpointer user_data)
{
	//FIXME
}


static void on_refresh_activate(GtkMenuItem *menuitem, gpointer user_data)
{
	update_userlist();
	update_grouplist();
}


static void on_about_activate(GtkMenuItem *menuitem, gpointer user_data)
{
	GtkDialog *aboutwin = GTK_DIALOG(create_gtk_samba_about_dialog("gwsam"));
	gtk_dialog_run(aboutwin);
	gtk_widget_destroy(GTK_WIDGET(aboutwin));
}

static GtkWidget* create_mainwindow (void)
{
	GtkWidget *vbox1;
	GtkWidget *mnu_connect;
	GtkWidget *menubar;
	GtkWidget *menuitem1;
	GtkWidget *menuitem1_menu;
	GtkWidget *new1;
	GtkWidget *separatormenuitem1;
	GtkWidget *quit;
	GtkWidget *policies;
	GtkWidget *policies_menu;
	GtkWidget *account;
	GtkWidget *user_rights;
	GtkWidget *audit;
	GtkWidget *separator1;
	GtkWidget *trust_relations;
	GtkWidget *menuitem3;
	GtkWidget *menuitem3_menu;
	GtkWidget *refresh;
	GtkWidget *menuitem4;
	GtkWidget *menuitem4_menu;
	GtkWidget *about;
	GtkWidget *vpaned;
	GtkWidget *scrolledwindow1;
	GtkWidget *user_list;
	GtkWidget *scrolledwindow2;
	GtkWidget *group_list;
	GtkWidget *statusbar;
	GtkAccelGroup *accel_group;

	accel_group = gtk_accel_group_new ();

	mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_default_size (GTK_WINDOW (mainwin), 642, 562);
	gtk_window_set_title (GTK_WINDOW (mainwin), "User Manager");

	vbox1 = gtk_vbox_new (FALSE, 0);
	gtk_container_add (GTK_CONTAINER (mainwin), vbox1);

	menubar = gtk_menu_bar_new ();
	gtk_box_pack_start (GTK_BOX (vbox1), menubar, FALSE, FALSE, 0);

	menuitem1 = gtk_menu_item_new_with_mnemonic ("_File");
	gtk_container_add (GTK_CONTAINER (menubar), menuitem1);

	menuitem1_menu = gtk_menu_new ();
	gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem1), menuitem1_menu);

	mnu_connect = gtk_menu_item_new_with_mnemonic ("_Connect");
	gtk_container_add (GTK_CONTAINER (menuitem1_menu), mnu_connect);

	mnu_disconnect = gtk_menu_item_new_with_mnemonic ("_Disconnect");
	gtk_widget_set_sensitive (mnu_disconnect, FALSE);
	gtk_container_add (GTK_CONTAINER (menuitem1_menu), mnu_disconnect);

	seldomain = gtk_menu_item_new_with_mnemonic("_Select Domain");
	gtk_widget_set_sensitive (seldomain, FALSE);
	gtk_container_add (GTK_CONTAINER (menuitem1_menu), seldomain);

	separatormenuitem1 = gtk_separator_menu_item_new ();
	gtk_container_add (GTK_CONTAINER (menuitem1_menu), separatormenuitem1);
	gtk_widget_set_sensitive (separatormenuitem1, FALSE);

	quit = gtk_image_menu_item_new_from_stock ("gtk-quit", accel_group);
	gtk_container_add (GTK_CONTAINER (menuitem1_menu), quit);

	menuitem1 = gtk_menu_item_new_with_mnemonic ("_User");
	gtk_container_add (GTK_CONTAINER (menubar), menuitem1);
	gtk_widget_set_sensitive (menuitem1, FALSE);

	menuitem1_menu = gtk_menu_new ();
	gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem1), menuitem1_menu);

	new1 = gtk_image_menu_item_new_from_stock ("gtk-new", accel_group);
	gtk_container_add (GTK_CONTAINER (menuitem1_menu), new1);



	policies = gtk_menu_item_new_with_mnemonic ("_Policies");
	gtk_container_add (GTK_CONTAINER (menubar), policies);
	gtk_widget_set_sensitive (policies, FALSE);

	policies_menu = gtk_menu_new ();
	gtk_menu_item_set_submenu (GTK_MENU_ITEM (policies), policies_menu);

	account = gtk_menu_item_new_with_mnemonic ("_Account...");
	gtk_container_add (GTK_CONTAINER (policies_menu), account);

	user_rights = gtk_menu_item_new_with_mnemonic ("_User Rights...");
	gtk_container_add (GTK_CONTAINER (policies_menu), user_rights);

	audit = gtk_menu_item_new_with_mnemonic ("A_udit...");
	gtk_container_add (GTK_CONTAINER (policies_menu), audit);

	separator1 = gtk_separator_menu_item_new ();
	gtk_container_add (GTK_CONTAINER (policies_menu), separator1);
	gtk_widget_set_sensitive (separator1, FALSE);

	trust_relations = gtk_menu_item_new_with_mnemonic ("_Trust relations");
	gtk_container_add (GTK_CONTAINER (policies_menu), trust_relations);

	menuitem3 = gtk_menu_item_new_with_mnemonic ("_View");
	gtk_container_add (GTK_CONTAINER (menubar), menuitem3);

	menuitem3_menu = gtk_menu_new ();
	gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem3), menuitem3_menu);

	refresh = gtk_image_menu_item_new_from_stock ("gtk-refresh", accel_group);
	gtk_container_add (GTK_CONTAINER (menuitem3_menu), refresh);
	gtk_widget_set_sensitive (refresh, FALSE);

	menuitem4 = gtk_menu_item_new_with_mnemonic ("_Help");
	gtk_container_add (GTK_CONTAINER (menubar), menuitem4);

	menuitem4_menu = gtk_menu_new ();
	gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem4), menuitem4_menu);

	about = gtk_menu_item_new_with_mnemonic ("_About");
	gtk_container_add (GTK_CONTAINER (menuitem4_menu), about);

	vpaned = gtk_vpaned_new ();
	gtk_box_pack_start (GTK_BOX (vbox1), vpaned, TRUE, TRUE, 0);

	scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
	gtk_paned_pack1 (GTK_PANED (vpaned), scrolledwindow1, FALSE, TRUE);

	user_list = gtk_tree_view_new ();
	gtk_container_add (GTK_CONTAINER (scrolledwindow1), user_list);

	scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
	gtk_paned_pack2 (GTK_PANED (vpaned), scrolledwindow2, TRUE, TRUE);

	group_list = gtk_tree_view_new ();
	gtk_container_add (GTK_CONTAINER (scrolledwindow2), group_list);

	statusbar = gtk_statusbar_new ();
	gtk_box_pack_start (GTK_BOX (vbox1), statusbar, FALSE, FALSE, 0);

	g_signal_connect ((gpointer) new1, "activate",
					  G_CALLBACK (on_new1_activate),
					  NULL);
	g_signal_connect ((gpointer) seldomain, "activate",
					  G_CALLBACK (on_select_domain_activate),
					  NULL);
	g_signal_connect ((gpointer) mnu_connect, "activate",
					  G_CALLBACK (on_connect_activate),
					  NULL);
	g_signal_connect ((gpointer) mnu_disconnect, "activate",
					  G_CALLBACK (on_disconnect_activate),
					  NULL);
	g_signal_connect ((gpointer) quit, "activate",
					  G_CALLBACK (on_quit_activate),
					  NULL);
	g_signal_connect ((gpointer) account, "activate",
					  G_CALLBACK (on_account_activate),
					  NULL);
	g_signal_connect ((gpointer) user_rights, "activate",
					  G_CALLBACK (on_user_rights_activate),
					  NULL);
	g_signal_connect ((gpointer) audit, "activate",
					  G_CALLBACK (on_audit_activate),
					  NULL);
	g_signal_connect ((gpointer) trust_relations, "activate",
					  G_CALLBACK (on_trust_relations_activate),
					  NULL);
	g_signal_connect ((gpointer) refresh, "activate",
					  G_CALLBACK (on_refresh_activate),
					  NULL);
	g_signal_connect ((gpointer) about, "activate",
					  G_CALLBACK (on_about_activate),
					  NULL);

	gtk_window_add_accel_group (GTK_WINDOW (mainwin), accel_group);

	return mainwin;
}

int main(int argc, char **argv)
{
	lp_load();
	setup_logging(argv[0], DEBUG_STDERR);

	gtk_init(&argc, &argv);
	mainwin = create_mainwindow();
	connect_sam();
	gtk_widget_show_all(mainwin);

	return gtk_event_loop();
}