1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00

r15408: Fix some small bugs in the GTK+ tools

Add utility function for connection to an interface
(This used to be commit 266f747220)
This commit is contained in:
Jelmer Vernooij 2006-05-03 09:11:36 +00:00 committed by Gerald (Jerry) Carter
parent 37aa2c5e8f
commit 86a2f18b96
8 changed files with 144 additions and 139 deletions

View File

@ -26,6 +26,9 @@
#include "librpc/rpc/dcerpc.h"
#include "auth/credentials/credentials.h"
/**
* Dialog error showing a WERROR
*/
void gtk_show_werror(GtkWidget *win, const char *message, WERROR err)
{
GtkWidget *dialog = gtk_message_dialog_new( GTK_WINDOW(win),
@ -38,6 +41,9 @@ void gtk_show_werror(GtkWidget *win, const char *message, WERROR err)
gtk_widget_destroy (dialog);
}
/**
* GTK+ dialog showing a NTSTATUS error
*/
void gtk_show_ntstatus(GtkWidget *win, const char *message, NTSTATUS status)
{
GtkWidget *dialog = gtk_message_dialog_new( GTK_WINDOW(win),
@ -50,7 +56,7 @@ void gtk_show_ntstatus(GtkWidget *win, const char *message, NTSTATUS status)
gtk_widget_destroy (dialog);
}
static void on_browse_activate (GtkButton *button, gpointer user_data)
static void on_browse_activate (GtkButton *button, gpointer user_data)
{
GtkRpcBindingDialog *rbd = user_data;
GtkWidget *shd = gtk_select_host_dialog_new(rbd->sam_pipe);
@ -117,8 +123,6 @@ static void gtk_rpc_binding_dialog_init (GtkRpcBindingDialog *gtk_rpc_binding_di
gtk_radio_button_set_group (GTK_RADIO_BUTTON (gtk_rpc_binding_dialog->transport_tcp_ip), transport_smb_group);
transport_smb_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (gtk_rpc_binding_dialog->transport_tcp_ip));
label1 = gtk_label_new ("Transport");
gtk_frame_set_label_widget (GTK_FRAME (frame_transport), label1);
@ -213,6 +217,12 @@ GType gtk_rpc_binding_dialog_get_type (void)
return mytype;
}
/**
* Create a new GTK+ dialog asking for binding information for
* DCE/RPC
*
* Optionally gets a sam pipe that will be used to look up users
*/
GtkWidget *gtk_rpc_binding_dialog_new (struct dcerpc_pipe *sam_pipe)
{
GtkRpcBindingDialog *d = GTK_RPC_BINDING_DIALOG ( g_object_new (gtk_rpc_binding_dialog_get_type (), NULL));
@ -291,7 +301,7 @@ GtkWidget *create_gtk_samba_about_dialog (const char *appname)
label3 = gtk_label_new_with_mnemonic ("Part of Samba <http://www.samba.org/>");
gtk_box_pack_start (GTK_BOX (dialog_vbox1), label3, FALSE, FALSE, 0);
label4 = gtk_label_new ("\302\251 1992-2005 The Samba Team");
label4 = gtk_label_new ("\302\251 1992-2006 The Samba Team");
gtk_box_pack_start (GTK_BOX (dialog_vbox1), label4, FALSE, FALSE, 0);
dialog_action_area1 = GTK_DIALOG (samba_about_dialog)->action_area;

View File

@ -22,7 +22,6 @@
#ifndef __GTK_SMB_H__
#define __GTK_SMB_H__
#define GTK_DISABLE_DEPRECATED
#include <gtk/gtk.h>

View File

@ -23,6 +23,7 @@
#include "librpc/gen_ndr/ndr_samr_c.h"
#include "gtk/common/select.h"
#include "gtk/common/gtk-smb.h"
#include "auth/credentials/credentials.h"
/* GtkSelectDomainDialog */
@ -260,3 +261,43 @@ GtkWidget *gtk_select_host_dialog_new (struct dcerpc_pipe *sam_pipe)
{
return GTK_WIDGET ( g_object_new (gtk_select_host_dialog_get_type (), NULL ));
}
/**
* Connect to a specific interface, but ask the user
* for information not specified
*/
struct dcerpc_pipe *gtk_connect_rpc_interface(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_table *table)
{
GtkRpcBindingDialog *d;
NTSTATUS status;
struct dcerpc_pipe *pipe;
struct cli_credentials *cred;
gint result;
d = GTK_RPC_BINDING_DIALOG(gtk_rpc_binding_dialog_new(NULL));
result = gtk_dialog_run(GTK_DIALOG(d));
if (result != GTK_RESPONSE_ACCEPT) {
gtk_widget_destroy(GTK_WIDGET(d));
return NULL;
}
cred = cli_credentials_init(mem_ctx);
cli_credentials_guess(cred);
cli_credentials_set_gtk_callbacks(cred);
status = dcerpc_pipe_connect_b(mem_ctx, &pipe,
gtk_rpc_binding_dialog_get_binding(d, mem_ctx),
table, cred, NULL);
if(!NT_STATUS_IS_OK(status)) {
gtk_show_ntstatus(NULL, "While connecting to interface", status);
gtk_widget_destroy(GTK_WIDGET(d));
talloc_free(mem_ctx);
return NULL;
}
gtk_widget_destroy(GTK_WIDGET(d));
return pipe;
}

View File

@ -22,8 +22,6 @@
#ifndef __GTK_SELECT_H__
#define __GTK_SELECT_H__
#ifdef HAVE_GTK
#define GTK_DISABLE_DEPRECATED
#include <gtk/gtk.h>
@ -80,7 +78,7 @@ GtkWidget *gtk_select_host_dialog_new (struct dcerpc_pipe *sam_pipe);
const char *gtk_select_host_dialog_get_host (GtkSelectHostDialog *d);
GType gtk_select_host_dialog_get_type (void);
#endif
struct dcerpc_interface_table;
struct dcerpc_pipe *gtk_connect_rpc_interface(TALLOC_CTX *mem_ctx, const struct dcerpc_interface_table *table);
#endif

View File

@ -23,6 +23,7 @@
#include "librpc/gen_ndr/ndr_epmapper_c.h"
#include "librpc/gen_ndr/ndr_mgmt_c.h"
#include "gtk/common/gtk-smb.h"
#include "gtk/common/select.h"
#include "auth/gensec/gensec.h"
/*
@ -166,40 +167,14 @@ static void on_refresh_clicked (GtkButton *btn, gpointer user_data)
refresh_eps();
}
static void on_connect_clicked(GtkButton *btn, gpointer user_data)
static void on_connect_clicked(GtkButton *btn, gpointer user_data)
{
GtkRpcBindingDialog *d;
const char *bs;
TALLOC_CTX *mem_ctx;
NTSTATUS status;
gint result;
struct cli_credentials *credentials;
TALLOC_CTX *mem_ctx = talloc_init("connect");
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));
epmapper_pipe = gtk_connect_rpc_interface(mem_ctx, &dcerpc_table_epmapper);
if (epmapper_pipe == NULL)
return;
}
mem_ctx = talloc_init("connect");
bs = gtk_rpc_binding_dialog_get_binding_string (d, mem_ctx);
credentials = cli_credentials_init(mem_ctx);
cli_credentials_guess(credentials);
cli_credentials_set_gtk_callbacks(credentials);
status = dcerpc_pipe_connect(talloc_autofree_context(), &epmapper_pipe, bs,
&dcerpc_table_epmapper,
credentials, NULL);
if (NT_STATUS_IS_ERR(status)) {
gtk_show_ntstatus(mainwin, "Error connecting to endpoint mapper", status);
goto fail;
}
gtk_widget_set_sensitive( mnu_refresh, True );
@ -210,11 +185,7 @@ static void on_connect_clicked(GtkButton *btn, gpointer user_data)
if (NT_STATUS_IS_ERR(status)) {
mgmt_pipe = NULL;
gtk_show_ntstatus(NULL, "Error connecting to mgmt interface over secondary connection", status);
goto fail;
}
fail:
gtk_widget_destroy(GTK_WIDGET(d));
}
static gboolean on_eps_select(GtkTreeSelection *selection,

View File

@ -22,12 +22,14 @@
#include "includes.h"
#include "librpc/gen_ndr/ndr_atsvc_c.h"
#include "gtk/common/gtk-smb.h"
#include "gtk/common/select.h"
#include "auth/credentials/credentials.h"
static struct dcerpc_pipe *at_pipe = NULL;
static GtkWidget *mainwin;
static GtkListStore *store_jobs;
static GtkWidget *tasks;
static GtkWidget *new_task;
static GtkWidget *entry_cmd;
static GtkWidget *entry_repeat_weekly;
static GtkWidget *entry_repeat_monthly;
@ -70,7 +72,6 @@ static void update_joblist(void)
}
talloc_free(mem_ctx);
gtk_widget_set_sensitive(tasks, TRUE);
}
static void on_job_select(GtkTreeSelection *sel, gpointer data)
@ -81,45 +82,12 @@ static void on_job_select(GtkTreeSelection *sel, gpointer data)
static void on_connect_activate(GtkMenuItem *menuitem, gpointer user_data)
{
GtkRpcBindingDialog *d;
NTSTATUS status;
struct cli_credentials *credentials;
gint result;
TALLOC_CTX *mem_ctx;
at_pipe = gtk_connect_rpc_interface(talloc_autofree_context(), &dcerpc_table_atsvc);
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));
if (!at_pipe)
return;
}
mem_ctx = talloc_init("gwcrontab_connect");
/* If connected, get list of jobs */
credentials = cli_credentials_init(mem_ctx);
cli_credentials_guess(credentials);
cli_credentials_set_gtk_callbacks(credentials);
status = dcerpc_pipe_connect_b(mem_ctx, &at_pipe,
gtk_rpc_binding_dialog_get_binding(d, mem_ctx),
&dcerpc_table_atsvc,
credentials, NULL);
if(!NT_STATUS_IS_OK(status)) {
gtk_show_ntstatus(mainwin, "Error while connecting to at service", status);
at_pipe = NULL;
gtk_widget_destroy(GTK_WIDGET(d));
talloc_free(mem_ctx);
return;
}
gtk_widget_destroy(GTK_WIDGET(d));
at_pipe = talloc_reference(talloc_autofree_context(), at_pipe);
talloc_free(mem_ctx);
gtk_widget_set_sensitive (new_task, TRUE);
update_joblist();
}
@ -129,12 +97,9 @@ static void on_quit_activate(GtkMenuItem *menuitem, gpointer user_data)
gtk_main_quit();
}
static GtkWidget* create_new_job_dialog (void);
void
on_new_activate (GtkMenuItem *menuitem,
gpointer user_data)
void on_new_activate (GtkMenuItem *menuitem, gpointer user_data)
{
GtkWidget *d = create_new_job_dialog();
gint result = gtk_dialog_run(GTK_DIALOG(d));
@ -176,9 +141,7 @@ on_new_activate (GtkMenuItem *menuitem,
}
void
on_delete_activate (GtkMenuItem *menuitem,
gpointer user_data)
void on_delete_activate(GtkMenuItem *menuitem, gpointer user_data)
{
GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tasks));
GtkTreeModel *model = GTK_TREE_MODEL(store_jobs);
@ -227,7 +190,6 @@ static GtkWidget* create_mainwindow (void)
GtkWidget *quit;
GtkWidget *task;
GtkWidget *task_menu;
GtkWidget *new;
GtkCellRenderer *renderer;
GtkTreeViewColumn *curcol;
GtkWidget *menuitem7;
@ -273,8 +235,9 @@ static GtkWidget* create_mainwindow (void)
task_menu = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (task), task_menu);
new = gtk_menu_item_new_with_mnemonic ("_New");
gtk_container_add (GTK_CONTAINER (task_menu), new);
new_task = gtk_menu_item_new_with_mnemonic ("_New");
gtk_container_add (GTK_CONTAINER (task_menu), new_task);
gtk_widget_set_sensitive (new_task, FALSE);
delete = gtk_menu_item_new_with_mnemonic ("_Delete");
gtk_widget_set_sensitive(delete, FALSE);
@ -343,7 +306,7 @@ static GtkWidget* create_mainwindow (void)
g_signal_connect ((gpointer) quit, "activate",
G_CALLBACK (on_quit_activate), NULL);
g_signal_connect ((gpointer) new, "activate",
g_signal_connect ((gpointer) new_task, "activate",
G_CALLBACK (on_new_activate), NULL);
g_signal_connect ((gpointer) delete, "activate",
G_CALLBACK (on_delete_activate), NULL);
@ -351,28 +314,23 @@ static GtkWidget* create_mainwindow (void)
G_CALLBACK (on_about_activate), NULL);
gtk_window_add_accel_group (GTK_WINDOW (mainwindow), accel_group);
gtk_widget_set_sensitive(tasks, FALSE);
return mainwindow;
}
void
on_chk_weekly_toggled (GtkToggleButton *togglebutton,
gpointer user_data)
void on_chk_weekly_toggled(GtkToggleButton *togglebutton, gpointer user_data)
{
gtk_widget_set_sensitive(entry_repeat_weekly, gtk_toggle_button_get_active(togglebutton));
}
void
on_chk_monthly_toggled (GtkToggleButton *togglebutton,
gpointer user_data)
void on_chk_monthly_toggled(GtkToggleButton *togglebutton, gpointer user_data)
{
gtk_widget_set_sensitive(entry_repeat_monthly, gtk_toggle_button_get_active(togglebutton));
}
static GtkWidget*create_new_job_dialog (void)
static GtkWidget *create_new_job_dialog (void)
{
GtkWidget *new_job_dialog;
GtkWidget *dialog_vbox1;

View File

@ -30,6 +30,8 @@ struct dcerpc_pipe *sam_pipe = NULL;
static struct policy_handle domain_handle;
GtkWidget *mainwin;
GtkWidget *seldomain;
GtkListStore *store_users;
GtkListStore *store_groups;
static GtkWidget *mnu_disconnect;
static void update_grouplist(void)
@ -48,11 +50,13 @@ static void update_userlist(void)
if(!sam_pipe) return;
gtk_list_store_clear(store_users);
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.in.max_size = (uint32_t)100;
r.out.resume_handle = &resume_handle;
status = dcerpc_samr_EnumDomainUsers(sam_pipe, mem_ctx, &r);
@ -68,7 +72,13 @@ static void update_userlist(void)
}
for (i=0;i<r.out.sam->count;i++) {
printf("Found: %s\n", r.out.sam->entries[i].name.string);
GtkTreeIter iter;
gtk_list_store_append(store_users, &iter);
gtk_list_store_set (store_users, &iter,
0, r.out.sam->entries[i].name.string,
1, r.out.sam->entries[i].name.string,
2, 0, -1);
/* FIXME: Query user info */
// if (!test_OpenUser(sam_pipe, mem_ctx, &sam_handle, r.out.sam->entries[i].idx)) {
@ -80,7 +90,7 @@ static void update_userlist(void)
static void on_new1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
/* FIXME */
}
static void on_select_domain_activate(GtkMenuItem *menuitem, gpointer user_data)
@ -106,40 +116,16 @@ static void on_select_domain_activate(GtkMenuItem *menuitem, gpointer user_data)
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;
}
NTSTATUS status;
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);
sam_pipe = gtk_connect_rpc_interface(talloc_autofree_context(), &dcerpc_table_samr);
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);
if (!sam_pipe)
return;
}
r.in.system_name = 0;
r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
@ -149,30 +135,26 @@ static void connect_sam(void)
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();
/* FIXME: Connect to default domain */
}
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)
@ -230,6 +212,8 @@ static GtkWidget* create_mainwindow (void)
GtkWidget *new1;
GtkWidget *separatormenuitem1;
GtkWidget *quit;
GtkCellRenderer *renderer;
GtkTreeViewColumn *curcol;
GtkWidget *policies;
GtkWidget *policies_menu;
GtkWidget *account;
@ -297,8 +281,6 @@ static GtkWidget* create_mainwindow (void)
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);
@ -350,12 +332,60 @@ static GtkWidget* create_mainwindow (void)
user_list = gtk_tree_view_new ();
gtk_container_add (GTK_CONTAINER (scrolledwindow1), user_list);
curcol = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(curcol, "Name");
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(curcol, renderer, True);
gtk_tree_view_append_column(GTK_TREE_VIEW(user_list), curcol);
gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
curcol = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(curcol, "Description");
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(curcol, renderer, True);
gtk_tree_view_append_column(GTK_TREE_VIEW(user_list), curcol);
gtk_tree_view_column_add_attribute(curcol, renderer, "text", 1);
curcol = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(curcol, "RID");
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(curcol, renderer, True);
gtk_tree_view_append_column(GTK_TREE_VIEW(user_list), curcol);
gtk_tree_view_column_add_attribute(curcol, renderer, "text", 1);
store_users = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);
gtk_tree_view_set_model(GTK_TREE_VIEW(user_list), GTK_TREE_MODEL(store_users));
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);
curcol = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(curcol, "Name");
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(curcol, renderer, True);
gtk_tree_view_append_column(GTK_TREE_VIEW(group_list), curcol);
gtk_tree_view_column_add_attribute(curcol, renderer, "text", 0);
curcol = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(curcol, "Description");
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(curcol, renderer, True);
gtk_tree_view_append_column(GTK_TREE_VIEW(group_list), curcol);
gtk_tree_view_column_add_attribute(curcol, renderer, "text", 1);
curcol = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(curcol, "RID");
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(curcol, renderer, True);
gtk_tree_view_append_column(GTK_TREE_VIEW(group_list), curcol);
gtk_tree_view_column_add_attribute(curcol, renderer, "text", 1);
store_groups = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);
gtk_tree_view_set_model(GTK_TREE_VIEW(group_list), GTK_TREE_MODEL(store_groups));
statusbar = gtk_statusbar_new ();
gtk_box_pack_start (GTK_BOX (vbox1), statusbar, FALSE, FALSE, 0);

View File

@ -22,9 +22,7 @@
#include "includes.h"
#include "gtk/common/gtk-smb.h"
GtkWidget*
create_user_edit_dialog (void)
GtkWidget* create_user_edit_dialog (void)
{
GtkWidget *user_edit_dialog;
GtkWidget *dialog_vbox1;